GenerateStatisticsCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
dl 0
loc 55
ccs 14
cts 14
cp 1
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 29 1
A execute() 0 17 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\Console\Commands;
7
8
use PhUml\Console\ConsoleProgressDisplay;
9
use PhUml\Generators\StatisticsGenerator;
10
use PhUml\Generators\StatisticsGeneratorConfiguration;
11
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command 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...
12
use Symfony\Component\Console\Exception\InvalidArgumentException;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Consol...nvalidArgumentException 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...
13
use Symfony\Component\Console\Input\InputArgument;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputArgument 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...
14
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputInterface 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...
15
use Symfony\Component\Console\Input\InputOption;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputOption 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...
16
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\OutputInterface 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...
17
18
/**
19
 * This command will generate a text file with the statistics of an OO codebase
20
 *
21
 * This command has 2 required arguments
22
 *
23
 * 1. `directory`. The path where your codebase lives
24
 * 2. `output`. The path to where the generated `png` image will be saved
25
 *
26
 * There is 1 option
27
 *
28
 * 1. `recursive`. If present it will look recursively within the `directory` provided
29
 */
30
final class GenerateStatisticsCommand extends Command
31
{
32
    /**
33
     * @throws InvalidArgumentException
34
     */
35 17
    protected function configure(): void
36
    {
37
        $this
38 17
            ->setName('phuml:statistics')
39 17
            ->setDescription('Generate statistics about the code of a given directory')
40 17
            ->setHelp(
41
                <<<HELP
42
Example:
43
    php bin/phuml phuml:statistics -r  ./src statistics.txt
44
45
    This example will scan the `./src` directory recursively for php files.
46
    It will generate the statistics and save them to the file `statistics.txt`.
47
HELP
48
            )
49 17
            ->addOption(
50
                'recursive',
51
                'r',
52
                InputOption::VALUE_NONE,
53
                'Look for classes in the given directory recursively'
54
            )
55 17
            ->addArgument(
56
                'directory',
57
                InputArgument::REQUIRED,
58
                'The directory to be scanned to generate the statistics'
59
            )
60 17
            ->addArgument(
61
                'output',
62
                InputArgument::REQUIRED,
63
                'The file name for your statistics file'
64
            )
65
        ;
66
    }
67
68 2
    protected function execute(InputInterface $input, OutputInterface $output): int
69
    {
70
        /** @var array{ recursive: bool } $options */
71 2
        $options = $input->getOptions();
72 2
        $configuration = new StatisticsGeneratorConfiguration($options, new ConsoleProgressDisplay($output));
73 2
        $generator = StatisticsGenerator::fromConfiguration($configuration);
74
75
        /**
76
         * @var array{
77
         *      directory: string,
78
         *      output: string
79
         * } $arguments
80
         */
81 2
        $arguments = $input->getArguments();
82 2
        $generator->generate(GeneratorInput::textFile($arguments));
83
84 1
        return self::SUCCESS;
85
    }
86
}
87