CsvExtractor   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 49
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A extract() 0 12 2
A current() 0 4 1
A key() 0 4 1
A next() 0 4 1
A rewind() 0 4 1
A valid() 0 4 1
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