UploadCommand::validateInput()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Dictionary\Features\PopulateStorage\Upload\Console;
6
7
use App\Dictionary\Features\PopulateStorage\Upload\FileAssert;
8
use App\Dictionary\Features\PopulateStorage\Upload\WordsStorageUpload;
9
use App\Dictionary\Features\PopulateStorage\Upload\WordsStorageUploadCriteria;
10
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...
11
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...
12
13
final class UploadCommand extends AbstractCommand
14
{
15
    protected static $defaultName = 'dictionary:upload';
16
17
    private WordsStorageUpload $wordsStorageUpload;
18
19
    public function __construct(WordsStorageUpload $wordsStorageUpload)
20
    {
21
        parent::__construct();
22
23
        $this->wordsStorageUpload = $wordsStorageUpload;
24
    }
25
26
    protected function configure(): void
27
    {
28
        $this->setDescription('Upload a new words and his definition to the storage.');
29
        $this->addArgument('file-path', InputArgument::REQUIRED, 'File path');
30
        $this->setHelp(
31
            <<<HELP
32
The command upload a new words and his definition to the storage 
33
    <info>php %command.full_name% file.csv</info>
34
HELP
35
        );
36
    }
37
38
    protected function doExecute(InputInterface $input): string
39
    {
40
        $criteria = new WordsStorageUploadCriteria((string) $input->getArgument('file-path'));
41
        $count = $this->wordsStorageUpload->execute($criteria);
42
43
        return sprintf('Upload %s words.', $count);
44
    }
45
46
    /**
47
     * @psalm-suppress PossiblyInvalidCast
48
     */
49
    protected function validateInput(InputInterface $input): void
50
    {
51
        FileAssert::assertCsvFile((string) $input->getArgument('file-path'));
52
    }
53
}
54