addDependency() публичный Метод

public addDependency ( SensioLabs\Deptrac\DependencyResult\DependencyInterface $dependency )
$dependency SensioLabs\Deptrac\DependencyResult\DependencyInterface
 public function testGetDependenciesAndInheritDependencies()
 {
     $dependencyResult = new DependencyResult();
     $dependencyResult->addDependency($dep1 = new DependencyResult\Dependency('A', 12, 'B'));
     $dependencyResult->addInheritDependency($dep2 = new DependencyResult\Dependency('A', 12, 'B'));
     $this->assertEquals([$dep1, $dep2], $dependencyResult->getDependenciesAndInheritDependencies());
 }
 public function testFlattenDependencies()
 {
     $astMap = $this->prophesize(AstMap::class);
     $astMap->getAstClassReferences()->willReturn([$this->getAstReference('classA'), $this->getAstReference('classB'), $this->getAstReference('classBaum'), $this->getAstReference('classWeihnachtsbaum'), $this->getAstReference('classGeschmückterWeihnachtsbaum')]);
     $dependencyResult = new DependencyResult();
     $dependencyResult->addDependency($classADep = $this->getDependency('classA'));
     $dependencyResult->addDependency($classBDep = $this->getDependency('classB'));
     $dependencyResult->addDependency($classBaumDep = $this->getDependency('classBaum'));
     $dependencyResult->addDependency($classWeihnachtsbaumsDep = $this->getDependency('classWeihnachtsbaumsA'));
     $astMap->getClassInherits('classA')->willReturn([]);
     $astMap->getClassInherits('classB')->willReturn([]);
     $astMap->getClassInherits('classBaum')->willReturn([]);
     $astMap->getClassInherits('classWeihnachtsbaum')->willReturn([AstInherit::newUses('classBaum', 3)]);
     $astMap->getClassInherits('classGeschmückterWeihnachtsbaum')->willReturn([new FlattenAstInherit(AstMap\AstInherit::newExtends('classBaum', 3), [AstInherit::newUses('classWeihnachtsbaum', 3)])]);
     (new DependencyInheritanceFlatter())->flattenDependencies($astMap->reveal(), $dependencyResult);
     $inheritDeps = array_filter($dependencyResult->getDependenciesAndInheritDependencies(), function ($v) {
         return $v instanceof InheritDependency;
     });
     $this->assertCount(1, $inheritDeps);
 }
 public function applyDependencies(AstParserInterface $astParser, AstMap $astMap, DependencyResult $dependencyResult)
 {
     foreach ($astMap->getAstClassReferences() as $classReference) {
         foreach ($astMap->getClassInherits($classReference->getClassName()) as $inherit) {
             if ($inherit instanceof FlattenAstInherit) {
                 continue;
             }
             $dependencyResult->addDependency(new Dependency($classReference->getClassName(), $inherit->getLine(), $inherit->getClassName()));
         }
     }
 }
Пример #4
0
 /**
  * @param array $dependenciesAsArray
  * @param array $classesInLayers
  * @param array $rulesetConfiguration
  * @param $expectedCount
  * @dataProvider dependencyProvider
  */
 public function testGetViolationsButNoViolations(array $dependenciesAsArray, array $classesInLayers, array $rulesetConfiguration, $expectedCount)
 {
     $dependencyResult = new DependencyResult();
     foreach ($this->createDependencies($dependenciesAsArray) as $dep) {
         $dependencyResult->addDependency($dep);
     }
     $classNameLayerResolver = $this->prophesize(ClassNameLayerResolverInterface::class);
     foreach ($classesInLayers as $classInLayer => $layers) {
         $classNameLayerResolver->getLayersByClassName($classInLayer)->willReturn($layers);
     }
     $this->assertCount($expectedCount, (new RulesetEngine())->getViolations($dependencyResult, $classNameLayerResolver->reveal(), ConfigurationRuleset::fromArray($rulesetConfiguration)));
 }
 public function applyDependencies(AstParserInterface $astParser, AstMap $astMap, DependencyResult $dependencyResult)
 {
     /* @var $astParser NikicPhpParser */
     assert($astParser instanceof NikicPhpParser === true);
     foreach ($astMap->getAstFileReferences() as $fileReference) {
         $uses = $this->getUseStatements($astParser, $fileReference);
         foreach ($fileReference->getAstClassReferences() as $astClassReference) {
             /** @var $uses EmittedDependency[] */
             $uses = array_merge($uses, $this->getInstanceOfStatements($astParser, $astClassReference), $this->getParamStatements($astParser, $astClassReference), $this->getNewStatements($astParser, $astClassReference), $this->getStaticPropertiesAccess($astParser, $astClassReference), $this->getStaticMethodCalls($astParser, $astClassReference));
             foreach ($uses as $emittedDependency) {
                 $dependencyResult->addDependency(new Dependency($astClassReference->getClassName(), $emittedDependency->getLine(), $emittedDependency->getClass()));
             }
         }
     }
 }