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

AbstractFileDriver::loadMetadataForClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Metadata\Driver;
4
5
/**
0 ignored issues
show
introduced by
Copyright notice must start with /*; but /** was found!
Loading history...
6
 * Base file driver implementation.
7
 *
8
 * @author Johannes M. Schmitt <[email protected]>
9
 */
10
abstract class AbstractFileDriver implements AdvancedDriverInterface
11
{
12
    /**
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...
13
     * @var FileLocatorInterface|FileLocator
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
14
     */
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
15
    private $locator;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
16
17
    public function __construct(FileLocatorInterface $locator)
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...
18
    {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
19
        $this->locator = $locator;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
20
    }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
21
22
    public function loadMetadataForClass(\ReflectionClass $class)
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...
23
    {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
24
        if (null === $path = $this->locator->findFileForClass($class, $this->getExtension())) {
0 ignored issues
show
introduced by
Assignments in condition should be surrounded by the extra pair of brackets
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
25
            return null;
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
28
        return $this->loadMetadataFromFile($class, $path);
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
29
    }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
30
31
    /**
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
32
     * {@inheritDoc}
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
33
     */
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...
34
    public function getAllClassNames()
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
35
    {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
36
        if (!$this->locator instanceof AdvancedFileLocatorInterface) {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
37
            throw new \RuntimeException('Locator "%s" must be an instance of "AdvancedFileLocatorInterface".');
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
38
        }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
39
40
        return $this->locator->findAllClasses($this->getExtension());
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
41
    }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
42
43
    /**
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
44
     * Parses the content of the file, and converts it to the desired metadata.
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
45
     *
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
46
     * @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...
47
     * @param string           $file
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...
48
     *
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
49
     * @return \Metadata\ClassMetadata|null
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
50
     */
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
51
    abstract protected function loadMetadataFromFile(\ReflectionClass $class, $file);
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
52
53
    /**
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
54
     * Returns the extension of the file.
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
55
     *
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
56
     * @return string
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
57
     */
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
58
    abstract protected function getExtension();
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
59
}
60