YamlConfigurationReader::readConfiguration()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 1
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