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
|
|
|
|