Completed
Push — master ( 9d1ab7...13f027 )
by Luis
04:13 queued 02:19
created

Generator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 4 1
A __construct() 0 3 1
A display() 0 6 2
A parseCode() 0 4 1
A attach() 0 3 1
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
8
namespace PhUml\Generators;
9
10
use LogicException;
11
use PhUml\Code\Structure;
12
use PhUml\Parser\CodeFinder;
13
use PhUml\Parser\CodeParser;
14
use PhUml\Processors\Processor;
15
16
/**
17
 * All generators will see the console commands as listeners that will provide feedback
18
 * to the end users about their progress
19
 *
20
 * @see ProcessorProgressDisplay for the details about the events that are tracked
21
 */
22
abstract class Generator
23
{
24
    /** @var ProcessorProgressDisplay */
25
    private $display;
26
27
    /** @var CodeParser */
28
    private $parser;
29
30 66
    public function __construct(CodeParser $parser)
31
    {
32 66
        $this->parser = $parser;
33 66
    }
34
35 54
    public function attach(ProcessorProgressDisplay $display): void
36
    {
37 54
        $this->display = $display;
38 54
    }
39
40
    /** @throws LogicException */
41 60
    protected function display(): ProcessorProgressDisplay
42
    {
43 60
        if (!$this->display) {
44 12
            throw new LogicException('No display was attached');
45
        }
46 48
        return $this->display;
47
    }
48
49
    /**
50
     * @throws \LogicException If the command is missing
51
     */
52 48
    protected function parseCode(CodeFinder $finder): Structure
53
    {
54 48
        $this->display()->runningParser();
55 48
        return $this->parser->parse($finder);
56
    }
57
58 48
    protected function save(Processor $processor, string $content, string $path): void
59
    {
60 48
        $this->display()->savingResult();
61 48
        $processor->saveToFile($content, $path);
62 48
    }
63
}
64