GrumphpConfigurationReader::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 3
nc 3
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 GrumphpConfigurationReader extends AbstractConfigurationReader
10
{
11
    /**
12
     * GrumphpConfigurationReader constructor.
13
     *
14
     * @param string $filePath
15
     */
16
    public function __construct(string $filePath = '')
17
    {
18
        if (!file_exists($filePath)) {
19
            $filePath = getcwd() . '/grumphp.yml';
20
            if (!file_exists($filePath)) {
21
                throw new FailedReadConfigurationException($filePath . ' does not exist!');
22
            }
23
        }
24
        parent::__construct($this->readConfiguration($filePath));
25
    }
26
27
    /**
28
     * @param string $filePath
29
     *
30
     * @return array
31
     */
32
    private function readConfiguration(string $filePath): array
33
    {
34
        $yamlString = Yaml::parseFile($filePath);
35
        if (is_array($yamlString) && is_array($yamlString['parameters']['tasks']['typoscriptlint'])) {
36
            return $yamlString['parameters']['tasks']['typoscriptlint'];
37
        }
38
        return [];
39
    }
40
}
41