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

AbstractFileDriver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 1 Features 2
Metric Value
c 4
b 1
f 2
dl 0
loc 50
wmc 5
lcom 1
cbo 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
loadMetadataFromFile() 0 1 ?
getExtension() 0 1 ?
A loadMetadataForClass() 0 8 2
A getAllClassNames() 0 8 2
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