alps-asd /
app-state-diagram
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace Koriym\AppStateDiagram; |
||||
| 6 | |||||
| 7 | use function basename; |
||||
| 8 | use function count; |
||||
| 9 | use function dirname; |
||||
| 10 | use function file_put_contents; |
||||
| 11 | use function passthru; |
||||
| 12 | use function sprintf; |
||||
| 13 | use function str_replace; |
||||
| 14 | |||||
| 15 | use const PHP_EOL; |
||||
| 16 | |||||
| 17 | final class PutDiagram |
||||
| 18 | { |
||||
| 19 | /** @var DrawDiagram */ |
||||
| 20 | private $draw; |
||||
| 21 | |||||
| 22 | public function __construct() |
||||
| 23 | { |
||||
| 24 | $this->draw = new DrawDiagram(); |
||||
| 25 | } |
||||
| 26 | |||||
| 27 | public function __invoke(Config $config): void |
||||
| 28 | { |
||||
| 29 | $profile = new Profile($config->profile, new LabelName()); |
||||
| 30 | $titleProfile = new Profile($config->profile, new LabelNameTitle()); |
||||
| 31 | $this->draw('', new LabelName(), $profile, null, null); |
||||
| 32 | $this->draw('.title', new LabelNameTitle(), $titleProfile, null, null); |
||||
| 33 | |||||
| 34 | (new DumpDocs())($profile, $config->profile, $config->outputMode); |
||||
| 35 | $index = new IndexPage($profile, $config->outputMode); |
||||
| 36 | file_put_contents($index->file, $index->content); |
||||
| 37 | echo "ASD generated. {$index->file}" . PHP_EOL; |
||||
| 38 | echo sprintf('Descriptors(%s), Links(%s)', count($profile->descriptors), count($profile->links)) . PHP_EOL; |
||||
| 39 | if ($config->hasTag) { |
||||
| 40 | $taggedSvg = $this->drawTag($profile, $config, new LabelName()); |
||||
| 41 | echo "Tagged ASD generated. {$taggedSvg}" . PHP_EOL; |
||||
| 42 | } |
||||
| 43 | } |
||||
| 44 | |||||
| 45 | private function draw(string $fileId, LabelNameInterface $labelName, AbstractProfile $profile, ?TaggedProfile $taggedProfile, ?string $color): void |
||||
| 46 | { |
||||
| 47 | $dot = ($this->draw)($profile, $labelName, $taggedProfile, $color); |
||||
| 48 | $extention = $fileId . '.dot'; |
||||
| 49 | $dotFile = str_replace(['.xml', '.json'], $extention, $profile->alpsFile); |
||||
| 50 | $this->convert($dotFile, $dot); |
||||
| 51 | } |
||||
| 52 | |||||
| 53 | private function drawTag(Profile $profile, Config $config, LabelName $labelName): string |
||||
| 54 | { |
||||
| 55 | $filteredProfile = new TaggedProfile($profile, $config->filter->or, $config->filter->and); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
$config->filter->or of type Koriym\AppStateDiagram\list is incompatible with the type array expected by parameter $orTags of Koriym\AppStateDiagram\T...dProfile::__construct().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 56 | $tagDot = $config->filter->color ? (new DrawDiagram())($profile, $labelName, $filteredProfile, $config->filter->color) : (new DrawDiagram())($profile, $labelName, $filteredProfile); |
||||
| 57 | $file = str_replace(['.xml', '.json'], '.dot', $config->profile); |
||||
| 58 | $svgFile = str_replace(['.xml', '.json'], '.svg', $config->profile); |
||||
| 59 | $tagFile = dirname($file) . '/tag_' . basename($file); |
||||
| 60 | file_put_contents($tagFile, $tagDot); |
||||
| 61 | $filteredSvg = dirname($svgFile) . '/tag_' . basename($svgFile); |
||||
| 62 | $this->convert($filteredSvg, $tagDot); |
||||
| 63 | |||||
| 64 | return $filteredSvg; |
||||
| 65 | } |
||||
| 66 | |||||
| 67 | private function convert(string $dotFile, string $dot): void |
||||
| 68 | { |
||||
| 69 | file_put_contents($dotFile, $dot); |
||||
| 70 | $svgFile = str_replace('dot', 'svg', $dotFile); |
||||
| 71 | $cmd = "dot -Tsvg {$dotFile} -o {$svgFile}"; |
||||
| 72 | passthru($cmd, $status); |
||||
| 73 | if ($status !== 0) { |
||||
| 74 | echo 'Warning: Graphviz error. https://graphviz.org/download/' . PHP_EOL; // @codeCoverageIgnore |
||||
| 75 | } |
||||
| 76 | } |
||||
| 77 | } |
||||
| 78 |