Completed
Push — master ( 797142...deecf0 )
by Luis
06:15 queued 02:52
created

GenerateClassDiagram::command()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
namespace PhUml\Actions;
8
9
use LogicException;
10
use PhUml\Parser\CodeFinder;
11
use PhUml\Parser\TokenParser;
12
use PhUml\Processors\GraphvizProcessor;
13
use PhUml\Processors\ImageProcessor;
14
15
class GenerateClassDiagram extends Action
16
{
17
    /** @var TokenParser */
18
    private $parser;
19
20
    /** @var GraphvizProcessor */
21
    private $dotProcessor;
22
23
    /** @var ImageProcessor */
24
    private $imageProcessor;
25
26 15
    public function __construct(TokenParser $parser, GraphvizProcessor $dotProcessor) {
27 15
        $this->parser = $parser;
28 15
        $this->dotProcessor = $dotProcessor;
29 15
    }
30
31 6
    public function setImageProcessor(ImageProcessor $imageProcessor): void
32
    {
33 6
        $this->imageProcessor = $imageProcessor;
34 6
    }
35
36
    /**
37
     * @throws LogicException If either the image processor or the command are missing
38
     */
39 12
    public function generate(CodeFinder $finder, string $imagePath): void
40
    {
41 12
        $this->command()->runningParser();
42 9
        $structure = $this->parser->parse($finder);
43 9
        $this->command()->runningProcessor($this->dotProcessor);
44 9
        $dotLanguage = $this->dotProcessor->process($structure);
45 9
        $this->command()->runningProcessor($this->imageProcessor());
46 6
        $image = $this->imageProcessor()->process($dotLanguage);
47 6
        $this->command()->savingResult();
48 6
        $this->imageProcessor->writeToDisk($image, $imagePath);
49 6
    }
50
51
    /** @throws LogicException */
52 9
    private function imageProcessor(): ImageProcessor
53
    {
54 9
        if (!$this->imageProcessor) {
55 3
            throw new LogicException('No image processor was provided');
56
        }
57 6
        return $this->imageProcessor;
58
    }
59
}
60