|
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; |
|
|
|
|
|
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
|
|
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
|
|
|
|
|
12
|
|
|
use Webmozart\Assert\Assert; |
|
|
|
|
|
|
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
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths