Completed
Push — master ( 86437d...3559e6 )
by diego
08:58
created

Yaml::legacyClassLoading()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.8204

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 3
cts 13
cp 0.2308
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 3.8204
1
<?php
2
3
declare(strict_types=1);
4
namespace HDNET\Importr\Service;
5
6
use Symfony\Component\Yaml\Exception\ParseException;
7
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
8
9
/**
10
 * Description of Yaml
11
 *
12
 * @author timlochmueller
13
 */
14
class Yaml
15
{
16
    /**
17
     * @param $input string
18
     *
19
     * @return array
20
     */
21 3
    public static function parse($input)
22
    {
23 3
        self::legacyClassLoading();
24
        try {
25 3
            $array = \Symfony\Component\Yaml\Yaml::parse($input);
26
            /**
27
             * The parser can return integer or string
28
             * if an number or a string is passed to it.
29
             * We always need an configuration array, so
30
             * we drop any other datatype here.
31
             */
32 2
            if (!\is_array($array)) {
33 2
                $array = [];
34
            }
35 1
        } catch (ParseException $e) {
36
            /**
37
             * @todo maybe log the error
38
             */
39 1
            $array = [];
40
        }
41 3
        return $array;
42
    }
43
44 3
    public static function legacyClassLoading()
45
    {
46 3
        if (!\class_exists(\Symfony\Component\Yaml\Yaml::class)) {
47
            $yamlComponentPath = ExtensionManagementUtility::extPath('importr', 'Resources/Private/Php/Yaml/');
48
            include_once $yamlComponentPath . 'Yaml.php';
49
            include_once $yamlComponentPath . 'Parser.php';
50
            include_once $yamlComponentPath . 'Inline.php';
51
            include_once $yamlComponentPath . 'Dumper.php';
52
            include_once $yamlComponentPath . 'Escaper.php';
53
            include_once $yamlComponentPath . 'Unescaper.php';
54
            include_once $yamlComponentPath . 'Exception/ExceptionInterface.php';
55
            include_once $yamlComponentPath . 'Exception/ParseException.php';
56
            include_once $yamlComponentPath . 'Exception/DumpException.php';
57
        }
58 3
    }
59
}
60