getLayersByClassName() public method

public getLayersByClassName ( $className )
示例#1
0
 /**
  * @param DependencyResult                $dependencyResult
  * @param ClassNameLayerResolverInterface $classNameLayerResolver
  * @param ConfigurationRuleset            $configurationRuleset
  *
  * @return RulesetViolation[]
  */
 public function getViolations(DependencyResult $dependencyResult, ClassNameLayerResolverInterface $classNameLayerResolver, ConfigurationRuleset $configurationRuleset)
 {
     $violations = [];
     foreach ($dependencyResult->getDependenciesAndInheritDependencies() as $dependency) {
         $layerNames = $classNameLayerResolver->getLayersByClassName($dependency->getClassA());
         foreach ($layerNames as $layerName) {
             foreach ($classNameLayerResolver->getLayersByClassName($dependency->getClassB()) as $layerNameOfDependency) {
                 if ($layerName == $layerNameOfDependency) {
                     continue;
                 }
                 if (in_array($layerNameOfDependency, $configurationRuleset->getAllowedDependendencies($layerName))) {
                     continue;
                 }
                 $violations[] = new RulesetViolation($dependency, $layerName, $layerNameOfDependency, '');
             }
         }
     }
     return $violations;
 }
 /**
  * @param AstMap                          $astMap
  * @param DependencyResult                $dependencyResult
  * @param ClassNameLayerResolverInterface $classNameLayerResolver
  *
  * @return array
  */
 private function calculateLayerDependencies(AstMap $astMap, DependencyResult $dependencyResult, ClassNameLayerResolverInterface $classNameLayerResolver)
 {
     $layersDependOnLayers = [];
     // all classes
     foreach ($astMap->getAstClassReferences() as $classReferences) {
         foreach ($classNameLayerResolver->getLayersByClassName($classReferences->getClassName()) as $classReferenceLayer) {
             $layersDependOnLayers[$classReferenceLayer] = [];
         }
     }
     // dependencies
     foreach ($dependencyResult->getDependenciesAndInheritDependencies() as $dependency) {
         $layersA = $classNameLayerResolver->getLayersByClassName($dependency->getClassA());
         $layersB = $classNameLayerResolver->getLayersByClassName($dependency->getClassB());
         if (empty($layersB)) {
             continue;
         }
         foreach ($layersA as $layerA) {
             if (!isset($layersDependOnLayers[$layerA])) {
                 $layersDependOnLayers[$layerA] = [];
             }
             foreach ($layersB as $layerB) {
                 if ($layerA == $layerB) {
                     continue;
                 }
                 if (!isset($layersDependOnLayers[$layerA][$layerB])) {
                     $layersDependOnLayers[$layerA][$layerB] = 1;
                     continue;
                 }
                 $layersDependOnLayers[$layerA][$layerB] = $layersDependOnLayers[$layerA][$layerB] + 1;
             }
         }
     }
     return $layersDependOnLayers;
 }