public function testGetSet() { $context = new DependencyContext($astMap = $this->prophesize(AstMap::class)->reveal(), [1, 2, 3], $dependencyResult = $this->prophesize(DependencyResult::class)->reveal(), $classNameLayerResolver = $this->prophesize(ClassNameLayerResolverInterface::class)->reveal()); $this->assertSame($astMap, $context->getAstMap()); $this->assertEquals([1, 2, 3], $context->getViolations()); $this->assertSame($dependencyResult, $context->getDependencyResult()); $this->assertSame($classNameLayerResolver, $context->getClassNameLayerResolver()); }
/** * @param DependencyContext $dependencyContext * @param OutputInterface $output * @param OutputFormatterInput $outputFormatterInput */ public function finish(DependencyContext $dependencyContext, OutputInterface $output, OutputFormatterInput $outputFormatterInput) { foreach ($dependencyContext->getViolations() as $violation) { if ($violation->getDependency() instanceof InheritDependency) { $this->handleInheritDependency($violation, $output); continue; } $this->handleDependeny($violation, $output); } if (count($dependencyContext->getViolations())) { $output->writeln(sprintf("\nFound <error>%s Violations</error>", count($dependencyContext->getViolations()))); } else { $output->writeln(sprintf("\nFound <info>%s Violations</info>", count($dependencyContext->getViolations()))); } }
/** * @param DependencyContext $dependencyContext * @param OutputInterface $output * @param OutputFormatterInput $outputFormatterInput */ public function finish(DependencyContext $dependencyContext, OutputInterface $output, OutputFormatterInput $outputFormatterInput) { $layerViolations = $this->calculateViolations($dependencyContext->getViolations()); $layersDependOnLayers = $this->calculateLayerDependencies($dependencyContext->getAstMap(), $dependencyContext->getDependencyResult(), $dependencyContext->getClassNameLayerResolver()); $graph = new \Fhaculty\Graph\Graph(); /** @var $vertices Vertex[] */ $vertices = []; // create a vertices foreach ($layersDependOnLayers as $layer => $layersDependOn) { if (!isset($vertices[$layer])) { $vertices[$layer] = $graph->createVertex($layer); } foreach ($layersDependOn as $layerDependOn => $layerDependOnCount) { if (!isset($vertices[$layerDependOn])) { $vertices[$layerDependOn] = $graph->createVertex($layerDependOn); } } } // createEdges foreach ($layersDependOnLayers as $layer => $layersDependOn) { foreach ($layersDependOn as $layerDependOn => $layerDependOnCount) { $vertices[$layer]->createEdgeTo($vertices[$layerDependOn]); if (isset($layerViolations[$layer], $layerViolations[$layer][$layerDependOn])) { $edge = $vertices[$layer]->getEdgesTo($vertices[$layerDependOn])->getEdgeFirst(); $edge->setAttribute('graphviz.label', $layerViolations[$layer][$layerDependOn]); $edge->setAttribute('graphviz.color', 'red'); } } } if ($outputFormatterInput->getOption(static::$argument_display)) { (new \Graphp\GraphViz\GraphViz())->display($graph); } if ($dumpImagePath = $outputFormatterInput->getOption(static::$argument_dump_image)) { $imagePath = (new \Graphp\GraphViz\GraphViz())->createImageFile($graph); rename($imagePath, $dumpImagePath); $output->writeln('<info>Image dumped to ' . realpath($dumpImagePath) . '</info>'); } if ($dumpDotPath = $outputFormatterInput->getOption(static::$argument_dump_dot)) { file_put_contents($dumpDotPath, (new \Graphp\GraphViz\GraphViz())->createScript($graph)); $output->writeln('<info>Script dumped to ' . realpath($dumpDotPath) . '</info>'); } if ($dumpHtmlPath = $outputFormatterInput->getOption(static::$argument_dump_html)) { file_put_contents($dumpHtmlPath, (new \Graphp\GraphViz\GraphViz())->createImageHtml($graph)); $output->writeln('<info>HTML dumped to ' . realpath($dumpHtmlPath) . '</info>'); } }