/** * @return PropertyNotDefinedIssue[] */ public function issues() { $classPropertiesAccessed = $this->method->propertyAccess()->properties(); $classPropertiesDefined = $this->class->properties(); $issues = array(); foreach ($classPropertiesAccessed as $property) { if (!isset($classPropertiesDefined[$property])) { $issues[] = new PropertyNotDefinedIssue($this->class, $this->method, new PhpClassProperty($property, Class_::MODIFIER_PUBLIC)); } } return $issues; }
/** * @return PhpMethod[] */ public function methods() { $methods = array(); $nodes = $this->class->asNode()->stmts; foreach ($nodes as $node) { if ($node->getType() === 'Stmt_ClassMethod') { /** @var Node\Stmt\ClassMethod $node */ $methods[$node->name] = new PhpMethod($node); } } return $methods; }
public function run() { $nodes = $this->file->sourceTree(); foreach ($nodes as &$node) { if ($node->getType() === 'Stmt_Class') { $class = new PhpClass($node); $methods = $class->methods(); foreach ($methods as $method) { $issues = (new PropertiesDefinedCheck($class, $method))->issues(); foreach ($issues as $issue) { $class = $issue->adjustedClass(); } } } } $this->file->setStringContent($this->nodesToSource($nodes)); }