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 basicDataProvider()
    {
        (yield [[new RulesetViolation(new InheritDependency('ClassA', 'ClassB', new Dependency('OriginalA', 12, 'OriginalB'), new FlattenAstInherit(AstInherit::newExtends('ClassInheritA', 3), [AstInherit::newExtends('ClassInheritB', 4), AstInherit::newExtends('ClassInheritC', 5), AstInherit::newExtends('ClassInheritD', 6)])), 'LayerA', 'LayerB')], '
                ClassA must not depend on ClassB (LayerA on LayerB)
                ClassInheritD::6 ->
                ClassInheritC::5 ->
                ClassInheritB::4 ->
                ClassInheritA::3 ->
                OriginalB::12

                Found 1 Violations
            ']);
        (yield [[new RulesetViolation(new Dependency('OriginalA', 12, 'OriginalB'), 'LayerA', 'LayerB')], '
                OriginalA::12 must not depend on OriginalB (LayerA on LayerB)

                Found 1 Violations
            ']);
        (yield [[], '

                Found 0 Violations
            ']);
    }
 /**
  * @param Node\Stmt\ClassLike $klass
  * @return AstInheritInterface[]
  */
 public static function findInheritances(Node\Stmt\ClassLike $klass)
 {
     $buffer = [];
     if ($klass instanceof Class_ && $klass->namespacedName instanceof Name) {
         if ($klass->extends instanceof Name) {
             $buffer[] = AstInherit::newExtends($klass->extends->toString(), $klass->extends->getLine());
         }
         if (!empty($klass->implements)) {
             foreach ($klass->implements as $impl) {
                 if (!$impl instanceof Name) {
                     continue;
                 }
                 $buffer[] = AstInherit::newImplements($impl->toString(), $impl->getLine());
             }
         }
     }
     if ($klass instanceof Trait_ || $klass instanceof Class_) {
         foreach ($klass->stmts as $traitUses) {
             if (!$traitUses instanceof Node\Stmt\TraitUse) {
                 continue;
             }
             foreach ($traitUses->traits as $traitUsage) {
                 if (!$traitUsage instanceof FullyQualified) {
                     continue;
                 }
                 $buffer[] = AstInherit::newUses($traitUsage->toString(), $traitUsage->getLine());
             }
         }
     }
     if ($klass instanceof Interface_ && isset($klass->namespacedName) && $klass->namespacedName instanceof Name) {
         foreach ($klass->extends as $extends) {
             $buffer[] = AstInherit::newExtends($extends->toString(), $extends->getLine());
         }
     }
     return $buffer;
 }