Passed
Pull Request — master (#22)
by Luis
24:40 queued 21:48
created

StatisticsGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 29
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 3
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,
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 37 at column 25
Loading history...
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