CsvFileLoader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setFile() 0 3 1
A getIteration() 0 8 3
1
<?php
2
3
namespace Doctrs\SonataImportBundle\Loaders;
4
5
6
use Symfony\Component\HttpFoundation\File\File;
7
use Symfony\Component\Process\Exception\InvalidArgumentException;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Proces...nvalidArgumentException 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...
8
9
class CsvFileLoader implements FileLoaderInterface {
10
11
    /** @var File $file  */
12
    protected $file = null;
13
14
    public function setFile(File $file) : FileLoaderInterface {
15
        $this->file = $file;
16
        return $this;
17
    }
18
19
    public function getIteration() {
20
        if (!$this->file) {
21
            throw new InvalidArgumentException('File not found');
22
        }
23
24
        $file = fopen($this->file->getRealPath(), 'r');
25
        while (($line = fgetcsv($file, 0, ',')) !== false) {
0 ignored issues
show
Bug introduced by
It seems like $file can also be of type false; however, parameter $handle of fgetcsv() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
        while (($line = fgetcsv(/** @scrutinizer ignore-type */ $file, 0, ',')) !== false) {
Loading history...
26
            yield $line;
27
        }
28
    }
29
30
}
31