Skip to content

Commit

Permalink
Option --graphviz-dump-image creates directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Brumann committed Nov 1, 2021
1 parent 6984a50 commit 7ab9b06
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/OutputFormatter/GraphVizOutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Qossmic\Deptrac\OutputFormatter;

use function base64_encode;
use function file_get_contents;
use phpDocumentor\GraphViz\Edge;
use phpDocumentor\GraphViz\Exception;
use phpDocumentor\GraphViz\Graph;
Expand All @@ -17,6 +15,8 @@
use Qossmic\Deptrac\RulesetEngine\Rule;
use Qossmic\Deptrac\RulesetEngine\Uncovered;
use Qossmic\Deptrac\RulesetEngine\Violation;
use function base64_encode;
use function file_get_contents;
use function sys_get_temp_dir;
use function tempnam;

Expand Down Expand Up @@ -74,6 +74,10 @@ public function finish(
}

if ($dumpImagePath = (string) $outputFormatterInput->getOption(self::DUMP_IMAGE)) {
$imageFile = new \SplFileInfo($dumpImagePath);
if(!is_dir($imageFile->getPath()) && !mkdir($imageFile->getPath())) {
throw new \LogicException(sprintf('Unable to dump image: Path "%s" does not exist and is not writable.', $imageFile->getPath()));
}
try {
$graph->export('png', $dumpImagePath);
$output->writeLineFormatted('<info>Image dumped to '.realpath($dumpImagePath).'</info>');
Expand Down

0 comments on commit 7ab9b06

Please sign in to comment.