Issues (9)

src/CsvFileIterator.php (5 issues)

Labels
Severity
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
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
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
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
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
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