GenerateCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Crossword\Features\Generator\Console;
6
7
use App\Crossword\Features\Generator\CrosswordGenerator;
8
use App\Crossword\Features\Generator\GenerateCriteria;
9
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...
10
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...
11
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...
12
use Webmozart\Assert\Assert;
0 ignored issues
show
Bug introduced by
The type Webmozart\Assert\Assert 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
14
final class GenerateCommand extends AbstractCommand
15
{
16
    private const LIMIT = '100';
17
18
    protected static $defaultName = 'crossword:generate';
19
20
    private CrosswordGenerator $crosswordGenerator;
21
22
    public function __construct(CrosswordGenerator $crosswordGenerator)
23
    {
24
        parent::__construct();
25
        $this->crosswordGenerator = $crosswordGenerator;
26
    }
27
28
    protected function configure(): void
29
    {
30
        $this->setDescription('Generate a new crossword.');
31
        $this->addArgument('type', InputArgument::REQUIRED, 'Type');
32
        $this->addArgument('language', InputArgument::REQUIRED, 'Language');
33
        $this->addArgument('word-count', InputArgument::REQUIRED, 'Word count');
34
        $this->addOption('limit', null, InputOption::VALUE_OPTIONAL, 'limit', self::LIMIT);
35
        $this->setHelp(
36
            <<<HELP
37
The command generate a new crossword 
38
    <info>php %command.full_name% normal en 2</info>
39
HELP
40
        );
41
    }
42
43
    protected function doExecute(InputInterface $input): string
44
    {
45
        $this->crosswordGenerator->generate(
46
            new GenerateCriteria(
47
                (string) $input->getArgument('type'),
48
                (string) $input->getArgument('language'),
49
                (int) $input->getArgument('word-count'),
50
                (int) $input->getOption('limit')
51
            )
52
        );
53
54
        return sprintf('Try to generate %d new crosswords.', (int) $input->getOption('limit'));
55
    }
56
57
    /**
58
     * @psalm-suppress PossiblyInvalidCast
59
     */
60
    protected function validateInput(InputInterface $input): void
61
    {
62
        Assert::greaterThan((int) $input->getArgument('word-count'), 1);
63
        if ($input->getOption('limit')) {
64
            Assert::lessThanEq((int) $input->getOption('limit'), self::LIMIT);
65
        }
66
    }
67
}
68