1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* PHP version 8.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 League\Pipeline\Pipeline; |
11
|
|
|
use PhUml\Console\Commands\GeneratorInput; |
12
|
|
|
use PhUml\Processors\OutputContent; |
13
|
|
|
use PhUml\Stages\CalculateStatistics; |
14
|
|
|
use PhUml\Stages\FindCode; |
15
|
|
|
use PhUml\Stages\ParseCode; |
16
|
|
|
use PhUml\Stages\SaveFile; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* It generates a text file with the statistics of an object oriented codebase |
20
|
|
|
* |
21
|
|
|
* It reports the number of classes and interfaces, number of private, public and protected methods |
22
|
|
|
* among other details |
23
|
|
|
*/ |
24
|
|
|
final class StatisticsGenerator |
25
|
|
|
{ |
26
|
4 |
|
public static function fromConfiguration(StatisticsGeneratorConfiguration $configuration): StatisticsGenerator |
27
|
|
|
{ |
28
|
4 |
|
return new StatisticsGenerator( |
29
|
4 |
|
new FindCode($configuration->codeFinder(), $configuration->display()), |
30
|
4 |
|
new ParseCode($configuration->codeParser(), $configuration->display()), |
31
|
4 |
|
new CalculateStatistics($configuration->statisticsProcessor(), $configuration->display()), |
32
|
4 |
|
new SaveFile($configuration->writer(), $configuration->display()), |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
4 |
|
private function __construct( |
37
|
|
|
private readonly FindCode $findCode, |
|
|
|
|
38
|
|
|
private readonly ParseCode $parseCode, |
39
|
|
|
private readonly CalculateStatistics $calculateStatistics, |
40
|
|
|
private readonly SaveFile $saveFile, |
41
|
|
|
) { |
42
|
|
|
} |
43
|
|
|
|
44
|
3 |
|
public function generate(GeneratorInput $input): void |
45
|
|
|
{ |
46
|
3 |
|
$pipeline = (new Pipeline()) |
47
|
3 |
|
->pipe($this->findCode) |
48
|
3 |
|
->pipe($this->parseCode) |
49
|
3 |
|
->pipe($this->calculateStatistics) |
50
|
3 |
|
->pipe(fn (OutputContent $content) => $this->saveFile->saveTo($content, $input->filePath())); |
51
|
|
|
|
52
|
3 |
|
$pipeline->process($input->codebaseDirectory()); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|