FinderFileStorageProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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