YamlConfigurationReader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A readConfiguration() 0 7 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Pluswerk\TypoScriptAutoFixer\Adapter\Configuration\Reader;
5
6
use Pluswerk\TypoScriptAutoFixer\Exception\FailedReadConfigurationException;
7
use Symfony\Component\Yaml\Yaml;
8
9
final class YamlConfigurationReader extends AbstractConfigurationReader
10
{
11
    public function __construct(string $filePath = '')
12
    {
13
        if (!file_exists($filePath)) {
14
            $filePath = getcwd() . '/typoscript-lint.yml';
15
            if (!file_exists($filePath)) {
16
                throw new FailedReadConfigurationException($filePath . ' does not exist!');
17
            }
18
        }
19
20
        parent::__construct($this->readConfiguration($filePath));
21
    }
22
23
    /**
24
     * @param string $filePath
25
     *
26
     * @return array
27
     */
28
    private function readConfiguration(string $filePath): array
29
    {
30
        $yamlString = Yaml::parseFile($filePath);
31
        if (is_array($yamlString)) {
32
            return $yamlString;
33
        }
34
        return [];
35
    }
36
}
37