WordsStorageUpload   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 29.4%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 38
ccs 5
cts 17
cp 0.294
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A execute() 0 9 2
A doExecute() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Dictionary\Features\PopulateStorage\Upload;
6
7
use App\Dictionary\Features\PopulateStorage\FileReader\FileReaderInterface;
8
use App\Dictionary\Features\PopulateStorage\SaveStorage\Message\SaveToStorageMessage;
9
use Psr\Log\LoggerInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Log\LoggerInterface 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\Messenger\MessageBusInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Messenger\MessageBusInterface 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 Throwable;
12
13
final class WordsStorageUpload
14
{
15
    private LoggerInterface $logger;
16
    private FileReaderInterface $fileReader;
17
    private MessageBusInterface $messageBus;
18
19
    public function __construct(
20
        FileReaderInterface $fileReader,
21
        MessageBusInterface $messageBus,
22
        LoggerInterface $logger
23
    ) {
24
        $this->logger = $logger;
25
        $this->fileReader = $fileReader;
26
        $this->messageBus = $messageBus;
27
    }
28
29 1
    public function execute(WordsStorageUploadCriteria $criteria): int
30
    {
31
        try {
32 1
            return $this->doExecute($criteria);
33 1
        } catch (Throwable $exception) {
34 1
            $this->logger->error($exception->getMessage());
35
        }
36
37 1
        return 0;
38
    }
39
40
    private function doExecute(WordsStorageUploadCriteria $criteria): int
41
    {
42
        $count = 0;
43
        foreach ($this->fileReader->read($criteria->filePath()) as $row) {
44
            if ($count) {
45
                $this->messageBus->dispatch(new SaveToStorageMessage($row[1], $row[2], $row[0]));
46
            }
47
            $count++;
48
        }
49
50
        return $count - 1;
51
    }
52
}
53