/** * {@inheritdoc} */ public function check(PhpFileInfo $phpFileInfo) { $violations = array(); foreach ($phpFileInfo->methodDefinitions() as $methodDefinition) { $ancestors = $this->ancestorResolver->getClassAncestors($phpFileInfo, $methodDefinition->parentName()); foreach ($ancestors as $ancestor) { if ($this->ruleSet->hasMethod($methodDefinition->name(), $ancestor)) { $violations[] = new Violation($methodDefinition, $phpFileInfo, $this->ruleSet->getMethod($methodDefinition->name(), $ancestor)->comment()); } } } return $violations; }
/** * {@inheritdoc} */ public function check(PhpFileInfo $phpFileInfo, RuleSet $ruleSet) { $violations = array(); foreach ($phpFileInfo->methodUsages() as $methodUsage) { $className = $methodUsage->className(); if ($ruleSet->hasMethod($methodUsage->name(), $className)) { $violations[] = new Violation($methodUsage, $phpFileInfo, $ruleSet->getMethod($methodUsage->name(), $className)->comment()); } $ancestors = $this->ancestorResolver->getClassAncestors($phpFileInfo, $methodUsage->className()); foreach ($ancestors as $ancestor) { if ($ruleSet->hasMethod($methodUsage->name(), $ancestor)) { $violations[] = new Violation(new MethodUsage($methodUsage->name(), $ancestor, $methodUsage->getLineNumber(), $methodUsage->isStatic()), $phpFileInfo, $ruleSet->getMethod($methodUsage->name(), $ancestor)->comment()); } } } return $violations; }
public function testGetMethod() { $methodDeprecation = $this->prophesize('SensioLabs\\DeprecationDetector\\FileInfo\\Deprecation\\MethodDeprecation'); $methodDeprecations = array('class' => array('method' => $methodDeprecation->reveal())); $ruleSet = new RuleSet(array(), array(), $methodDeprecations); $this->assertSame($methodDeprecation->reveal(), $ruleSet->getMethod('method', 'class')); $this->assertNull($ruleSet->getMethod('someOtherMethod', 'class')); }