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

StatisticsGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generateStatistics() 0 4 1
A __construct() 0 4 1
A generate() 0 5 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 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