YamlDriver   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 52
ccs 19
cts 20
cp 0.95
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 4 1
C getAllClassNames() 0 26 7
1
<?php
2
3
namespace Drest\Mapping\Driver;
4
5
use Doctrine\Common\Annotations;
6
use Drest\DrestException;
7
use Drest\Mapping\Annotation;
8
use Drest\Mapping;
9
use Symfony\Component\Yaml\Parser as YamlParser;
10
11
/**
12
 * The YamlDriver reads a configuration file (config.yaml) rather than annotations.
13
 */
14
class YamlDriver extends PhpDriver
15
{
16
17 5
    public function __construct($paths)
18
    {
19 5
        parent::__construct($paths);
20 5
    }
21
22
    /**
23
     * Factory method for the Annotation Driver
24
     *
25
     * @param  array|string $paths
26
     * @return self
27
     */
28 5
    public static function create($paths = [])
29
    {
30 5
        return new self($paths);
31
    }
32
33
    /**
34
     * Get all the metadata class names known to this driver.
35
     * @return array
36
     * @throws DrestException
37
     * @throws DriverException
38
     */
39 4
    public function getAllClassNames()
40
    {
41 4
        if (empty($this->classes)) {
42 4
            if (empty($this->paths)) {
43
                throw DrestException::pathToConfigFilesRequired();
44
            }
45
46 4
            $yamlParser = new YamlParser();
47 4
            foreach ($this->paths as $path)
48
            {
49 4
                if(!file_exists($path)) {
50 2
                    throw DriverException::configurationFileDoesntExist($path);
51
                }
52
53 2
                $resources = $yamlParser->parse(file_get_contents($path));
54
55 2
                if($resources === false || empty($resources)) {
56 1
                    throw DriverException::configurationFileIsInvalid('Yaml');
57
                }
58
59 1
                $this->classes = array_merge($this->classes, (array) $resources);
60 1
            }
61 1
        }
62
63 1
        return array_keys($this->classes);
64
    }
65
}
66