|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Dictionary\Features\PopulateStorage\Populate\Console; |
|
6
|
|
|
|
|
7
|
|
|
use App\Dictionary\Features\PopulateStorage\Populate\FileAssert; |
|
8
|
|
|
use App\Dictionary\Features\PopulateStorage\Populate\WordsStoragePopulate; |
|
9
|
|
|
use App\Dictionary\Features\PopulateStorage\Populate\WordsStoragePopulateCriteria; |
|
10
|
|
|
use RuntimeException; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
|
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
|
|
13
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
final class PopulateCommand extends AbstractCommand |
|
16
|
|
|
{ |
|
17
|
|
|
protected static $defaultName = 'dictionary:populate'; |
|
18
|
|
|
|
|
19
|
|
|
private string $filePath; |
|
20
|
|
|
private array $dictionaryList; |
|
21
|
|
|
private WordsStoragePopulate $wordsStoragePopulate; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct(WordsStoragePopulate $wordsStoragePopulate, array $dictionaryList) |
|
24
|
|
|
{ |
|
25
|
|
|
parent::__construct(); |
|
26
|
|
|
|
|
27
|
|
|
$this->filePath = ''; |
|
28
|
|
|
$this->wordsStoragePopulate = $wordsStoragePopulate; |
|
29
|
|
|
$this->dictionaryList = $dictionaryList; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function configure(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$this->setDescription('Populate a new words to the storage.'); |
|
35
|
|
|
$this->addArgument('language', InputArgument::REQUIRED, 'Language code'); |
|
36
|
|
|
$this->addOption('file-path', null, InputOption::VALUE_OPTIONAL, 'File path'); |
|
37
|
|
|
$this->setHelp( |
|
38
|
|
|
<<<HELP |
|
39
|
|
|
The command populate a new words to the storage |
|
40
|
|
|
<info>php %command.full_name% ua</info> |
|
41
|
|
|
<info>php %command.full_name% ua --file-path=file.txt</info> |
|
42
|
|
|
HELP |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function doExecute(InputInterface $input): string |
|
47
|
|
|
{ |
|
48
|
|
|
$criteria = new WordsStoragePopulateCriteria((string) $input->getArgument('language'), $this->filePath); |
|
49
|
|
|
$count = $this->wordsStoragePopulate->execute($criteria); |
|
50
|
|
|
|
|
51
|
|
|
return sprintf('Populate %s words.', $count); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @psalm-suppress PossiblyInvalidCast |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function validateInput(InputInterface $input): void |
|
58
|
|
|
{ |
|
59
|
|
|
if ($this->filePath = (string) $input->getOption('file-path')) { |
|
60
|
|
|
FileAssert::assertTxtFile((string) $input->getOption('file-path')); |
|
61
|
|
|
|
|
62
|
|
|
return; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if (!array_key_exists((string) $input->getArgument('language'), $this->dictionaryList)) { |
|
66
|
|
|
throw new RuntimeException('Dictionary is not found for words populate.'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$this->filePath = $this->dictionaryList[(string) $input->getArgument('language')]; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
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