Completed
Push — master ( b3acba...04c2f9 )
by Matteo
02:23
created

FilesystemIterator::setIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Mattbit\Flat\Storage;
4
5
use Mattbit\Flat\Model\Document;
6
use Mattbit\Flat\Storage\EncoderInterface;
7
8
class FilesystemIterator implements \Iterator {
9
10
    /**
11
     * @var EncoderInterface
12
     */
13
    protected $encoder;
14
15 5
    public function __construct(EncoderInterface $encoder, $path)
16
    {
17 5
        $this->encoder = $encoder;
18 5
        $this->iterator = new \GlobIterator($path, \FilesystemIterator::CURRENT_AS_PATHNAME);
0 ignored issues
show
Bug introduced by
The property iterator does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19 5
    }
20
21 1
    public function current()
22
    {
23 1
        $data = file_get_contents($this->iterator->current());
24
25 1
        return $this->encoder->decode($data);
26
    }
27
28 1
    public function key()
29
    {
30 1
        return $this->iterator->key();
31
    }
32
33 1
    public function next()
34
    {
35 1
    return $this->iterator->next();
36
    }
37
38 1
    public function rewind()
39
    {
40 1
        return $this->iterator->rewind();
41
    }
42
43 1
    public function valid()
44
    {
45 1
        return $this->iterator->valid();
46
    }
47
48 5
    public function setIterator(\Iterator $iterator)
49
    {
50 5
        $this->iterator = $iterator;
51 5
    }
52
}
53