Passed
Pull Request — master (#9)
by Luis
13:24
created

StatisticsGenerator::generateStatistics()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.0
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;
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...
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 15
    public static function fromConfiguration(StatisticsGeneratorConfiguration $configuration): StatisticsGenerator
27
    {
28 15
        return new StatisticsGenerator(
29 15
            new FindCode($configuration->codeFinder(), $configuration->display()),
30 15
            new ParseCode($configuration->codeParser(), $configuration->display()),
31
            new CalculateStatistics($configuration->statisticsProcessor(), $configuration->display()),
32
            new SaveFile($configuration->writer(), $configuration->display()),
33
        );
34
    }
35
36
    private function __construct(
37
        private FindCode $findCode,
38
        private ParseCode $parseCode,
39
        private CalculateStatistics $calculateStatistics,
40
        private SaveFile $saveFile,
41
    ) {
42 12
    }
43
44 12
    public function generate(GeneratorInput $input): void
45 9
    {
46 9
        $pipeline = (new Pipeline())
47 9
            ->pipe($this->findCode)
48
            ->pipe($this->parseCode)
49 9
            ->pipe($this->calculateStatistics)
50
            ->pipe(fn (OutputContent $content) => $this->saveFile->saveTo($content, $input->filePath()));
51 9
52 9
        $pipeline->process($input->codebaseDirectory());
53
    }
54
}
55