UploadCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 39
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validateInput() 0 3 1
A __construct() 0 5 1
A configure() 0 6 1
A doExecute() 0 6 1
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