Passed
Branch master (79d24d)
by Johannes
02:27
created

FileLocator::findAllClasses()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 21
rs 8.7624
cc 5
eloc 12
nc 7
nop 1
1
<?php
2
3
namespace Metadata\Driver;
4
5
class FileLocator implements AdvancedFileLocatorInterface
0 ignored issues
show
introduced by
Copyright notice missing
Loading history...
introduced by
Missing class doc comment
Loading history...
6
{
7
    private $dirs;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
8
9
    public function __construct(array $dirs)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
10
    {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
11
        $this->dirs = $dirs;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
12
    }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
13
14
    public function getDirs()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
15
    {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
16
        return $this->dirs;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
17
    }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
18
19
    /**
0 ignored issues
show
introduced by
Missing short description in doc comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
20
     * @param \ReflectionClass $class
0 ignored issues
show
introduced by
Missing parameter comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
21
     * @param string           $extension
0 ignored issues
show
introduced by
Missing parameter comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
22
     *
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
23
     * @return string|null
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
24
     */
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
25
    public function findFileForClass(\ReflectionClass $class, $extension)
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
26
    {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
27
        foreach ($this->dirs as $prefix => $dir) {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
28
            if ('' !== $prefix && 0 !== strpos($class->getNamespaceName(), $prefix)) {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
29
                continue;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
30
            }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
31
32
            $len = '' === $prefix ? 0 : strlen($prefix) + 1;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
33
            $path = $dir.'/'.str_replace('\\', '.', substr($class->name, $len)).'.'.$extension;
0 ignored issues
show
introduced by
Concat operator must be surrounded by spaces.
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
34
            if (file_exists($path)) {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
35
                return $path;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
36
            }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
37
        }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
38
39
        return null;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
40
    }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
41
42
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$extension" missing
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
43
     * {@inheritDoc}
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
44
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
45
    public function findAllClasses($extension)
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
46
    {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
47
        $classes = array();
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
48
        foreach ($this->dirs as $prefix => $dir) {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
49
            /** @var $iterator \RecursiveIteratorIterator|\SplFileInfo[] */
0 ignored issues
show
introduced by
The open comment tag must be the only content on the line
Loading history...
introduced by
Missing short description in doc comment
Loading history...
introduced by
The close comment tag must be the only content on the line
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
50
            $iterator = new \RecursiveIteratorIterator(
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
51
                new \RecursiveDirectoryIterator($dir),
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
52
                \RecursiveIteratorIterator::LEAVES_ONLY
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
53
            );
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
54
            $nsPrefix = $prefix !== '' ? $prefix.'\\' : '';
0 ignored issues
show
introduced by
Concat operator must be surrounded by spaces.
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
55
            foreach ($iterator as $file) {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
56
                if (($fileName = $file->getBasename('.'.$extension)) == $file->getBasename()) {
0 ignored issues
show
introduced by
Concat operator must be surrounded by spaces.
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
57
                    continue;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
58
                }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
59
60
                $classes[] = $nsPrefix.str_replace('.', '\\', $fileName);
0 ignored issues
show
introduced by
Concat operator must be surrounded by spaces.
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
61
            }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
62
        }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
63
64
        return $classes;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
65
    }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
66
}
67