FileIterator::next()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace FMUP\Import\Iterator;
3
4
use \FMUP\Import\Exception;
5
6
/**
7
 * Permet de parcourir un fichier ligne par ligne
8
 *
9
 * @author csanz
10
 *
11
 */
12
class FileIterator implements \Iterator
13
{
14
15
    protected $path;
16
17
    private $fHandle;
18
19
    private $current;
20
21
    private $line;
22
23 7
    public function __construct($path = "")
24
    {
25 7
        $this->setPath($path);
26 7
    }
27
28 7
    public function setPath($path)
29
    {
30 7
        $this->path = $path;
31 7
    }
32
33 2 View Code Duplication
    public function rewind()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35 2
        if (!file_exists($this->path)) {
36 1
            throw new Exception("Le fichier specifie n'existe pas ou est introuvable");
37
        }
38 1
        $this->line = -1;
39 1
        $this->fHandle = fopen($this->path, "r");
40 1
        rewind($this->fHandle);
41 1
        $this->next();
42 1
    }
43
44 1
    public function current()
45
    {
46 1
        return $this->current;
47
    }
48
49 1
    public function next()
50
    {
51 1
        $this->current = fgets($this->fHandle);
52 1
        $this->line++;
53 1
    }
54
55 1
    public function valid()
56
    {
57 1
        if (feof($this->fHandle)) {
58 1
            fclose($this->fHandle);
59 1
            return false;
60
        }
61 1
        return true;
62
    }
63
64 1
    public function key()
65
    {
66 1
        return $this->line;
67
    }
68
}
69