Passed
Pull Request — master (#23)
by
unknown
13:36 queued 10:51
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 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromConfiguration() 0 7 1
A __construct() 0 6 1
A generate() 0 9 1
1
<?php declare(strict_types=1);
2
/**
3
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
4
 */
5
6
namespace PhUml\Generators;
7
8
use League\Pipeline\Pipeline;
0 ignored issues
show
Bug introduced by
The type League\Pipeline\Pipeline was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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