CsvExtractor::current()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Extraload\Extractor;
4
5
class CsvExtractor implements ExtractorInterface
6
{
7
    private $file;
8
9
    public function __construct(\SplFileObject $file, $delimiter = ',', $enclosure = '"')
10
    {
11
        $this->file = $file;
12
        $this->file->setFlags(\SplFileObject::SKIP_EMPTY | \SplFileObject::READ_AHEAD | \SplFileObject::DROP_NEW_LINE | \SplFileObject::READ_CSV);
13
        $this->file->setCsvControl($delimiter, $enclosure);
14
    }
15
16
    public function extract()
17
    {
18
        if ($this->file->eof()) {
19
            return;
20
        }
21
22
        $data = $this->current();
23
24
        $this->next();
25
26
        return $data;
27
    }
28
29
    public function current()
30
    {
31
        return $this->file->current();
32
    }
33
34
    public function key()
35
    {
36
        return $this->file->key();
37
    }
38
39
    public function next()
40
    {
41
        return $this->file->next();
42
    }
43
44
    public function rewind()
45
    {
46
        return $this->file->rewind();
47
    }
48
49
    public function valid()
50
    {
51
        return $this->file->valid();
52
    }
53
}
54