Completed
Push — master ( 8e1797...9bbc25 )
by Luis
05:11 queued 03:17
created

GenerateStatistics   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 18
cts 19
cp 0.9474
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 8 1
A command() 0 6 2
A attach() 0 3 1
A __construct() 0 4 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
namespace PhUml\Actions;
8
9
use LogicException;
10
use PhUml\Parser\CodeFinder;
11
use PhUml\Parser\TokenParser;
12
use PhUml\Processors\StatisticsProcessor;
13
14
class GenerateStatistics
15
{
16
    /** @var TokenParser */
17
    private $parser;
18
19
    /** @var StatisticsProcessor */
20
    private $processor;
21
22
    /** @var CanGenerateStatistics */
23
    private $command;
24
25 6
    public function __construct(TokenParser $parser, StatisticsProcessor $processor)
26
    {
27 6
        $this->parser = $parser;
28 6
        $this->processor = $processor;
29 6
    }
30
31 6
    public function attach(CanGenerateStatistics $command): void
32
    {
33 6
        $this->command = $command;
34 6
    }
35
36
    /** @throws LogicException If the command is missing */
37 6
    public function generate(CodeFinder $finder, string $filePath): void
38
    {
39 6
        $this->command()->runningParser();
40 6
        $structure = $this->parser->parse($finder);
41 6
        $this->command()->runningProcessor($this->processor);
42 6
        $statistics = $this->processor->process($structure);
43 6
        $this->command()->savingResult();
44 6
        $this->processor->writeToDisk($statistics, $filePath);
45 6
    }
46
47
    /** @throws LogicException */
48 6
    private function command(): CanGenerateStatistics
49
    {
50 6
        if (!$this->command) {
51
            throw new LogicException('No command was attached');
52
        }
53 6
        return $this->command;
54
    }
55
}