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

FilesystemIterator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 45
rs 10
c 0
b 0
f 0
ccs 18
cts 18
cp 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A current() 0 6 1
A key() 0 4 1
A next() 0 4 1
A rewind() 0 4 1
A valid() 0 4 1
A setIterator() 0 4 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