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

GenerateClassDiagram   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setImageProcessor() 0 3 1
A __construct() 0 3 1
A generate() 0 10 1
A imageProcessor() 0 6 2
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