/** * ClassDiff constructor. * * @param string $currentFilePath * @param string $currentClassName * @param ClassGenerator $newClassGenerator */ public function __construct($currentFilePath, $currentClassName, ClassGenerator $newClassGenerator) { $this->currentFilePath = $currentFilePath; $this->currentClassName = $currentClassName; $this->currentClassCode = file_get_contents($currentFilePath); $this->currentClassGenerator = $this->getGeneratorFromReflection(new ClassReflection($currentClassName)); $this->newClassGenerator = $newClassGenerator; /* * PHP Reflections don't take into account use statements, so an entire * plugin is needed just for that. //shakes head */ $parser = new Parser(new Lexer()); $nodes = $parser->parse($this->currentClassCode); foreach ($nodes as $node) { /** @var $node Namespace_ */ if (get_class($node) == 'PhpParser\\Node\\Stmt\\Namespace_') { /** @var Use_ $stmt */ foreach ($node->stmts as $stmt) { if (get_class($stmt) == 'PhpParser\\Node\\Stmt\\Use_') { /** @var UseUse $use */ foreach ($stmt->uses as $use) { $this->currentClassGenerator->addUse($use->name->toString()); } } } } } if (in_array($this->currentClassGenerator->getExtendedClass(), $this->currentClassGenerator->getUses())) { $extended = new \ReflectionClass($this->currentClassGenerator->getExtendedClass()); $this->currentClassGenerator->setExtendedClass($extended->getShortName()); } }
public function testExtendedClassAccessors() { $classGenerator = new ClassGenerator(); $classGenerator->setExtendedClass('ExtendedClass'); $this->assertEquals($classGenerator->getExtendedClass(), 'ExtendedClass'); }