Passed
Push — 1.1 ( 13f027 )
by Luis
06:39
created

StatisticsGenerator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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
8
namespace PhUml\Generators;
9
10
use PhUml\Code\Structure;
11
use PhUml\Parser\CodeFinder;
12
use PhUml\Parser\CodeParser;
13
use PhUml\Processors\StatisticsProcessor;
14
15
/**
16
 * It generates a text file with the statistics of an object oriented codebase
17
 *
18
 * It reports the number of classes and interfaces, number of private, public and protected methods
19
 * among other details
20
 */
21
class StatisticsGenerator extends Generator
22
{
23
    /** @var StatisticsProcessor */
24
    private $statisticsProcessor;
25
26 15
    public function __construct(CodeParser $parser, StatisticsProcessor $statisticsProcessor)
27
    {
28 15
        parent::__construct($parser);
29 15
        $this->statisticsProcessor = $statisticsProcessor;
30 15
    }
31
32
    /**
33
     * The process to generate a text file with statistics is as follows
34
     *
35
     * 1. The parser produces a collection of classes and interfaces
36
     * 2. The `statistics` processor takes this collection and creates a summary
37
     * 4. The text file with the statistics is saved to the given path
38
     *
39
     * @throws \PhUml\Templates\TemplateFailure If Twig fails
40
     * @throws \LogicException If the command is missing
41
     */
42 12
    public function generate(CodeFinder $finder, string $statisticsFilePath): void
43
    {
44 12
        $this->display()->start();
45 9
        $statistics = $this->generateStatistics($this->parseCode($finder));
46 9
        $this->save($this->statisticsProcessor, $statistics, $statisticsFilePath);
47 9
    }
48
49 9
    private function generateStatistics(Structure $structure): string
50
    {
51 9
        $this->display()->runningProcessor($this->statisticsProcessor);
52 9
        return $this->statisticsProcessor->process($structure);
53
    }
54
}
55