Passed
Push — master ( c103e2...560387 )
by Emmanuel
03:39
created

Reader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 84
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getConfigValues() 0 4 1
A getEntities() 0 4 1
A parseAndValidateConfig() 0 8 1
1
<?php
2
/**
3
 * neuralyzer : Data Anonymization Library and CLI Tool
4
 *
5
 * PHP Version 7.1
6
 *
7
 * @author Emmanuel Dyan
8
 * @author Rémi Sauvat
9
 * @copyright 2018 Emmanuel Dyan
10
 *
11
 * @package edyan/neuralyzer
12
 *
13
 * @license GNU General Public License v2.0
14
 *
15
 * @link https://github.com/edyan/neuralyzer
16
 */
17
18
namespace Edyan\Neuralyzer\Configuration;
19
20
use Symfony\Component\Config\Definition\Processor;
21
use Symfony\Component\Config\FileLocator;
22
use Symfony\Component\Yaml\Yaml;
23
24
/**
25
 * Configuration Reader
26
 */
27
class Reader
28
{
29
    /**
30
     * Configuration file name
31
     *
32
     * @var string
33
     */
34
    protected $configFileName;
35
36
    /**
37
     * Define the directories to search in. Only the first file found is taken into account
38
     * Can be defined via the constructor
39
     *
40
     * @var array
41
     */
42
    protected $configDirectories;
43
44
    /**
45
     * Configuration file name
46
     *
47
     * @var string|array
48
     */
49
    protected $configFilePath;
50
51
    /**
52
     * Stores the config values
53
     *
54
     * @var array
55
     */
56
    protected $configValues = [];
57
58
59
    /**
60
     * Set a few properties, open the config file and parse it
61
     *
62
     * @param string $configFileName
63
     * @param array  $configDirectories
64
     */
65 24
    public function __construct(string $configFileName, array $configDirectories = ['.'])
66
    {
67 24
        $this->configFileName = $configFileName;
68 24
        $this->configDirectories = $configDirectories;
69
70 24
        $locator = new FileLocator($this->configDirectories);
71 24
        $this->configFilePath = $locator->locate($this->configFileName);
72
73 23
        $this->parseAndValidateConfig();
74 22
    }
75
76
77
    /**
78
     * Getter
79
     *
80
     * @return array Config Values
81
     */
82 21
    public function getConfigValues()
83
    {
84 21
        return $this->configValues;
85
    }
86
87
88
    /**
89
     * Return the list of entites
90
     *
91
     * @return array
92
     */
93 7
    public function getEntities(): array
94
    {
95 7
        return array_keys($this->configValues['entities']);
96
    }
97
98
99
    /**
100
     * Parse and validate the configuration
101
     */
102 23
    protected function parseAndValidateConfig()
103
    {
104 23
        $this->configValues = Yaml::parse(file_get_contents($this->configFilePath));
0 ignored issues
show
Documentation Bug introduced by
It seems like \Symfony\Component\Yaml\...$this->configFilePath)) of type * is incompatible with the declared type array of property $configValues.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
105
106 23
        $processor = new Processor();
107 23
        $configuration = new ConfigDefinition();
108 23
        $processor->processConfiguration($configuration, [$this->configValues]);
109 22
    }
110
}
111