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

GenerateStatistics::generate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 1
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\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
}