SensioLabs\Deptrac\OutputFormatter\GraphVizOutputFormatter::finish PHP Метод

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

public finish ( DependencyContext $dependencyContext, Symfony\Component\Console\Output\OutputInterface $output, OutputFormatterInput $outputFormatterInput )
$dependencyContext SensioLabs\Deptrac\DependencyContext
$output Symfony\Component\Console\Output\OutputInterface
$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>');
        }
    }