/** * @param string $namespace * @param Use_[] $uses * @param PhpParserClass $class * @param File $file */ public function __construct($namespace, array $uses, PhpParserClass $class, File $file) { $this->namespace = $namespace; $this->file = $file; $this->node = $class; $this->uses = $uses; $this->fqn = join('\\', array_filter([$namespace, $class->name])); $this->resolveNames(); if (NULL === $this->fqParent && isset($class->extends)) { throw new \RuntimeException('Something is amiss, resolved parent name and actual parent differ in ' . $file->getSplFile()->getRealPath() . ':' . $class->getLine()); } if (count($this->implements) !== count($class->implements)) { throw new \RuntimeException('Something is amiss, resolved ' . count($this->implements) . ' interface(s) but found ' . count($class->implements) . ' actual interface(s) in ' . $file->getSplFile()->getRealPath() . ':' . $class->getLine()); } }
/** * @param string $namespace * @param Use_[] $uses * @param PhpParserInterface $interface * @param File $file */ public function __construct($namespace, array $uses, PhpParserInterface $interface, File $file) { $this->namespace = $namespace; $this->file = $file; $this->node = $interface; $this->uses = $uses; $this->fqn = join('\\', array_filter([$namespace, $interface->name])); $this->resolveNames(); if (count($this->extends) !== count($interface->extends)) { throw new \RuntimeException('Something is amiss, resolved ' . count($this->extends) . ' extend(s) but found ' . count($interface->extends) . ' actual extend(s) in ' . $file->getSplFile()->getRealPath() . ':' . $interface->getLine()); } }
/** * 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); } } }
public function enterNode(Node $node) { if ($node instanceof Namespace_ && NULL !== $node->name) { $this->currentNamespace = join('\\', $node->name->parts); } else { if ($node instanceof Use_ && $node->type === Use_::TYPE_NORMAL) { $this->currentUseStatements[] = $node; } else { if ($node instanceof PhpParserClass || $node instanceof PhpParserInterface) { /** @var ParsedObject|NULL $object */ $object = NULL; if ($node instanceof PhpParserClass) { $object = new ParsedClass($this->currentNamespace, $this->currentUseStatements, $node, $this->currentFile); } else { if ($node instanceof PhpParserInterface) { $object = new ParsedInterface($this->currentNamespace, $this->currentUseStatements, $node, $this->currentFile); } } if (NULL !== $object) { try { $this->addObject($object); } catch (ObjectAlreadyExistsException $e) { $existingObject = $this->getObjectByFqn($object->getName()); $msg = 'Multiple declarations of the same type are not supported. Symbol ' . $object->getName() . ' from ' . $this->currentFile->getSplFile()->getRealPath() . ':' . $node->getLine(); if ($existingObject instanceof ParsedObject) { $msg .= ' already found in ' . $existingObject->getFile()->getSplFile()->getRealPath() . ':' . $existingObject->getNode()->getLine() . ' ; only the first ' . 'encounter is used'; } else { if ($existingObject instanceof ReflectedObject) { $msg .= ' clashes with internal ' . strtolower($existingObject->getKind()) . ' ' . $existingObject->getName(); } else { throw new \RuntimeException('Unknown existing object ' . $existingObject->getName()); } } $this->project->getLogger()->warning($msg); } } } } } }
/** * Return an array with serialize discrete values * * @return array */ public function toArray() { $data = ['file' => $this->file->getSplFile()->getRealPath(), 'lines' => $this->getLines(), 'lineSegment' => $this->getLineSegment()->toArray()]; return $data; }