CsvFileIterator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 14
c 1
b 0
f 0
dl 0
loc 42
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A rewind() 0 5 1
A key() 0 3 1
A valid() 0 3 1
A current() 0 3 1
A __construct() 0 3 1
A next() 0 4 1
A __destruct() 0 3 1
1
<?php
2
/**
3
 * @author: jiangyi
4
 * @date: 下午3:03 2018/11/27
5
 */
6
7
namespace Hello;
8
9
class CsvFileIterator implements \Iterator
10
{
11
    protected $file;
12
    protected $key = 0;
13
    protected $current;
14
15
    public function __construct($file)
16
    {
17
        $this->file = fopen($file, 'r');
18
    }
19
20
    public function __destruct()
21
    {
22
        fclose($this->file);
0 ignored issues
show
Bug introduced by
It seems like $this->file can also be of type boolean; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
        fclose(/** @scrutinizer ignore-type */ $this->file);
Loading history...
23
    }
24
25
    public function rewind()
26
    {
27
        rewind($this->file);
0 ignored issues
show
Bug introduced by
It seems like $this->file can also be of type boolean; however, parameter $handle of rewind() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        rewind(/** @scrutinizer ignore-type */ $this->file);
Loading history...
28
        $this->current = fgetcsv($this->file);
0 ignored issues
show
Bug introduced by
It seems like $this->file can also be of type boolean; however, parameter $handle of fgetcsv() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
        $this->current = fgetcsv(/** @scrutinizer ignore-type */ $this->file);
Loading history...
29
        $this->key = 0;
30
    }
31
32
    public function valid()
33
    {
34
        return !feof($this->file);
0 ignored issues
show
Bug introduced by
It seems like $this->file can also be of type boolean; however, parameter $handle of feof() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        return !feof(/** @scrutinizer ignore-type */ $this->file);
Loading history...
35
    }
36
37
    public function key()
38
    {
39
        return $this->key;
40
    }
41
42
    public function current()
43
    {
44
        return $this->current;
45
    }
46
47
    public function next()
48
    {
49
        $this->current = fgetcsv($this->file);
0 ignored issues
show
Bug introduced by
It seems like $this->file can also be of type boolean; however, parameter $handle of fgetcsv() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
        $this->current = fgetcsv(/** @scrutinizer ignore-type */ $this->file);
Loading history...
50
        $this->key++;
51
    }
52
}
53