Completed
Push — master ( d7c858...c3a5e7 )
by Markus
02:53
created

StringOrFileList::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Mathielen\ImportEngineBundle\DependencyInjection;
3
4
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;
5
6
class StringOrFileList implements \ArrayAccess
7
{
8
9
    /**
10
     * @var array
11
     */
12
    private $listOrStringsOrFiles;
13
14
    public function __construct(array $listOrStringsOrFiles)
15
    {
16
        $this->listOrStringsOrFiles = $listOrStringsOrFiles;
17
18
        foreach ($this->listOrStringsOrFiles as $k=>&$v) {
19
            if (is_dir($v)) {
20
                $iterator = new RecursiveDirectoryIterator($v, \FilesystemIterator::KEY_AS_PATHNAME);
21
                $iterator = new \RecursiveIteratorIterator($iterator);
22
23
                /** @var \Symfony\Component\Finder\SplFileInfo $file */
24
                foreach ($iterator as $file) {
25
                    if (is_file($file)) {
26
                        $this->listOrStringsOrFiles[$file->getRelativePathname()] = $file;
27
                    }
28
                }
29
30
                unset($this->listOrStringsOrFiles[$k]);
31
            } elseif (is_file($v)) {
32
                $v = new \SplFileInfo($v);
33
            }
34
        }
35
    }
36
37
    public function offsetExists($offset)
38
    {
39
        return isset($listOrStringsOrFiles[$offset]);
0 ignored issues
show
Bug introduced by
The variable $listOrStringsOrFiles seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
40
    }
41
42
    public function offsetGet($offset)
43
    {
44
        $v = $this->listOrStringsOrFiles[$offset];
45
        if ($v instanceof \SplFileInfo) {
46
            return file_get_contents($v);
47
        }
48
49
        return $v;
50
    }
51
52
    public function offsetSet($offset, $value)
53
    {
54
        // TODO: Implement offsetSet() method.
55
    }
56
57
    public function offsetUnset($offset)
58
    {
59
        // TODO: Implement offsetUnset() method.
60
    }
61
62
}
63