FileIterator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 17.54 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 10
loc 57
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setPath() 0 4 1
A rewind() 10 10 2
A current() 0 4 1
A next() 0 5 1
A valid() 0 8 2
A key() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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