FinderFileStorageProvider::getIterator()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 6
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Mathielen\ImportEngine\Storage\Provider;
4
5
use Mathielen\ImportEngine\Storage\Factory\StorageFactoryInterface;
6
use Symfony\Component\Finder\Finder;
7
use Mathielen\ImportEngine\ValueObject\StorageSelection;
8
9
class FinderFileStorageProvider extends FileStorageProvider implements \IteratorAggregate
10
{
11
    /**
12
     * @var Finder
13
     */
14
    private $finder;
15
16 10
    public function __construct(Finder $finder, StorageFactoryInterface $storageFactory = null)
17
    {
18 10
        parent::__construct($storageFactory);
19
20 10
        $this->finder = $finder;
21 10
    }
22
23
    public function getIterator()
24
    {
25
        $files = array();
26
        foreach ($this->finder->files() as $file) {
27
            $item = new StorageSelection(new \SplFileInfo($file), $file->getFilename(), $file->getFilename());
28
            $files[] = $item;
29
        }
30
31
        return new \ArrayIterator($files);
32
    }
33
}
34