CsvFileReader::read()   A
last analyzed

Complexity

Conditions 4
Paths 14

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 13
ccs 0
cts 8
cp 0
rs 10
cc 4
nc 14
nop 1
crap 20
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Dictionary\Infrastructure\FileReader;
6
7
use App\Dictionary\Features\PopulateStorage\FileReader\FileReaderInterface;
8
use App\Dictionary\Features\PopulateStorage\FileReader\OpenFileException;
9
use Generator;
10
11
final class CsvFileReader implements FileReaderInterface
12
{
13
    public function read(string $filePath): Generator
14
    {
15
        try {
16
            $file = fopen($filePath, 'rb');
17
            if (!$file) {
0 ignored issues
show
introduced by
$file is of type resource, thus it always evaluated to false.
Loading history...
18
                throw new OpenFileException($filePath);
19
            }
20
21
            while (!feof($file)) {
22
                yield fgetcsv($file);
23
            }
24
        } finally {
25
            $file && fclose($file);
26
        }
27
    }
28
}
29