/**
  * @param Project $project
  */
 public function analyze(Project $project)
 {
     foreach ($this->graph->getObjects() as $object) {
         if ($object instanceof ParsedInterface) {
             foreach ($object->getMethods() as $method) {
                 if ($method->getMethod()->isAbstract()) {
                     $report = new StringReport('Access type for interface method ' . $object->getName() . '::' . $method->getNameAndParamsSignature() . ' must be ommmited in ' . $object->getFile()->getSplFile()->getRealPath() . ':' . $object->getInterface()->getLine());
                     $report->setSourceFragment(new SourceFragment($object->getFile(), new Lines($method->getMethod()->getAttribute('startLine') - 1 - $this->sourceContext, $method->getMethod()->getAttribute('endLine') - 1 + $this->sourceContext, $method->getMethod()->getAttribute('startLine') - 1)));
                     $project->addReport($report);
                 }
             }
         }
     }
 }
 /**
  * @param Project $project
  */
 public function analyze(Project $project)
 {
     $this->project = $project;
     $traverser = new NodeTraverser();
     $traverser->addVisitor($this);
     foreach ($project->getFiles() as $file) {
         $this->currentFile = $file;
         $traverser->traverse($file->getTree());
         foreach ($this->variables as $variable) {
             $report = new StringReport('Variable used in constructing raw SQL, is it escaped?');
             $line = $variable->getAttribute('startLine') - 1;
             $report->setSourceFragment(new SourceFragment($file, new Lines($line - $this->sourceContext, $line + $this->sourceContext, $line)));
             $project->addReport($report);
         }
     }
 }
Esempio n. 3
0
 /**
  * Called when entering a node.
  *
  * Return value semantics:
  *  * null:      $node stays as-is
  *  * otherwise: $node is set to the return value
  *
  * @param Node $node Node
  *
  * @return null|Node Node
  */
 public function enterNode(Node $node)
 {
     if ($node instanceof Node\Stmt\Catch_) {
         $this->subNodeTraverser->traverse($node->stmts);
         $nonComments = $this->nonCommentCounterVisitor->getNonCommentStatements();
         if (0 === $nonComments) {
             $report = new StringReport('Empty catch block found');
             $line = $node->getAttribute('startLine') - 1;
             $report->setSourceFragment(new SourceFragment($this->currentFile, new Lines($line - $this->sourceContext, $line + $this->sourceContext, $line)));
             $this->project->addReport($report);
         }
     }
 }
 /**
  * Called when entering a node.
  *
  * Return value semantics:
  *  * null:      $node stays as-is
  *  * otherwise: $node is set to the return value
  *
  * @param Node $node Node
  *
  * @return null|Node Node
  */
 public function enterNode(Node $node)
 {
     if ($node instanceof New_) {
         if ($node->class instanceof Variable) {
             $msg = 'Dynamic class instantiation with variable ';
             if ($node->class->name instanceof Variable) {
                 $msg .= 'variable $' . $node->class->name->name;
             } else {
                 $msg .= '$' . $node->class->name;
             }
             $report = new StringReport($msg . ' in ' . $this->currentFile->getSplFile()->getFilename() . ':' . $node->class->getLine());
             $report->setSourceFragment(new SourceFragment($this->currentFile, new Lines($node->class->getAttribute('startLine') - 1 - $this->sourceContext, $node->class->getAttribute('endLine') - 1 + $this->sourceContext, $node->class->getAttribute('startLine') - 1)));
             $this->project->addReport($report);
         }
     }
 }