Example #1
0
 /**
  * Process the file, finding all functions within and running the processors
  * on each function.
  *
  * @param  array<SmellInterface> $processors
  * @return int
  */
 public function process(array $processors)
 {
     $statements = $this->parseCode();
     if ($statements instanceof Error === true) {
         // Report error to project and cancel processing.
         $this->project->addParseError($this->fileName, $statements);
         return static::RESULT_ERROR;
     }
     $functions = $this->filterAbstractFunctions($this->discover(array('PhpParser\\Node\\Stmt\\ClassMethod', 'PhpParser\\Node\\Stmt\\Function_'), $statements));
     // If there are no functions, exit early.
     if (count($functions) === 0) {
         return static::RESULT_EMPTY;
     }
     // Process each function individually.
     $smellCount = 0;
     foreach ($functions as $function) {
         $this->setCurrentFunction($this->getFunctionName($function));
         foreach ($processors as $processor) {
             $smellCount += $processor->process($function, $this);
         }
     }
     return $smellCount > 0 ? static::RESULT_SMELLS : static::RESULT_OK;
 }
Example #2
0
 /**
  * @covers ::addParseError
  * @covers ::getParseErrors
  */
 public function testAddAndGetParseErrors()
 {
     $project = new Project(array(), array(), false);
     // No errors by default.
     $this->assertCount(0, $project->getParseErrors());
     // Add some.
     $project->addParseError('fileA', $a = new Error(''));
     $project->addParseError('fileB', $b = new Error(''));
     $this->assertCount(2, $errors = $project->getParseErrors());
     $this->assertSame(array('fileA' => $a, 'fileB' => $b), $errors);
 }