YamlAdapter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dump() 0 3 1
A load() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Biurad opensource projects.
7
 *
8
 * PHP version 7.2 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 Biurad Group (https://biurad.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Biurad\DependencyInjection\Adapters;
19
20
use Nette\DI\Config\Adapters\NeonAdapter;
21
use Nette\Utils\FileSystem;
22
use Nette\Neon;
23
24
/**
25
 * Reading and generating Yaml files for DI.
26
 *
27
 * @author Divine Niiquaye Ibok <[email protected]>
28
 */
29
final class YamlAdapter extends \Nette\Di\Config\Adapter
30
{
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function load(string $file): array
35
    {
36
        // So yaml syntax could work properly
37
        $contents = \str_replace(
38
            ['~', '\'false\'', '\'true\'', '"false"', '"true"'],
39
            ['null', 'false', 'true', 'false', 'true'],
40
            FileSystem::read($file)
41
        );
42
43
        return (new NeonAdapter())->process((array) Neon\Neon::decode($contents));
44
    }
45
46
    /**
47
     * Generates configuration in NEON format.
48
     */
49
    public function dump(array $data): string
50
    {
51
        return (new NeonAdapter())->dump($data);
52
    }
53
}
54