Passed
Push — union-types ( b56600 )
by Luis
14:03
created

StatisticsGenerator::fromConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 10
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 7.4
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\Parser\CodeFinder;
13
use PhUml\Parser\CodeParser;
14
use PhUml\Processors\OutputWriter;
15
use PhUml\Processors\StatisticsProcessor;
16
use PhUml\Stages\CalculateStatistics;
17
use PhUml\Stages\FindCode;
18
use PhUml\Stages\ParseCode;
19
use PhUml\Stages\SaveFile;
20
use PhUml\Templates\TemplateFailure;
21
22
/**
23
 * It generates a text file with the statistics of an object oriented codebase
24
 *
25
 * It reports the number of classes and interfaces, number of private, public and protected methods
26
 * among other details
27
 */
28
final class StatisticsGenerator
29
{
30
    private CodeFinder $codeFinder;
31
32
    private CodeParser $codeParser;
33
34
    private StatisticsProcessor $statisticsProcessor;
35
36
    private OutputWriter $writer;
37
38
    public static function fromConfiguration(StatisticsGeneratorConfiguration $configuration): StatisticsGenerator
39
    {
40
        return new StatisticsGenerator(
41
            $configuration->codeFinder(),
42
            $configuration->codeParser(),
43
            $configuration->statisticsProcessor(),
44
            $configuration->writer()
45
        );
46
    }
47
48
    private function __construct(
49
        CodeFinder $codeFinder,
50
        CodeParser $codeParser,
51
        StatisticsProcessor $statisticsProcessor,
52
        OutputWriter $writer
53
    ) {
54
        $this->codeFinder = $codeFinder;
55
        $this->codeParser = $codeParser;
56
        $this->statisticsProcessor = $statisticsProcessor;
57
        $this->writer = $writer;
58
    }
59
60
    /**
61
     * It generates a text file with statistics
62
     *
63
     * @throws TemplateFailure If Twig fails
64
     */
65
    public function generate(GeneratorInput $input): void
66
    {
67
        $pipeline = (new Pipeline())
68
            ->pipe(new FindCode($this->codeFinder, $input->display()))
69
            ->pipe(new ParseCode($this->codeParser, $input->display()))
70
            ->pipe(new CalculateStatistics($this->statisticsProcessor, $input->display()))
71
            ->pipe(new SaveFile($this->writer, $input->outputFile(), $input->display()));
72
73
        $pipeline->process($input->directory());
74
    }
75
}
76