Passed
Push — master ( 4c267c...1bfd55 )
by Pierrick
10:36
created

Nacl::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * This file is part of NACL.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2019 Nuglif (2018) Inc.
9
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
10
 * @author    Pierrick Charron <[email protected]>
11
 * @author    Charle Demers <[email protected]>
12
 */
13
14
declare(strict_types=1);
15
16
namespace Nuglif\Nacl;
17
18
class Nacl
19
{
20
    private static array $macros = [];
21
22 1
    public static function registerMacro(MacroInterface $macro): void
23
    {
24 1
        self::$macros[] = $macro;
25
    }
26
27 591
    public static function createParser(): Parser
28
    {
29 591
        $parser = new Parser();
30 591
        $parser->registerMacro(new Macros\Env());
31 591
        $parser->registerMacro(new Macros\Constant());
32
33 591
        foreach (self::$macros as $macro) {
34 8
            $parser->registerMacro($macro);
35
        }
36
37 591
        return $parser;
38
    }
39
40 542
    public static function parse(string $str): mixed
41
    {
42 542
        return self::createParser()->parse($str);
43
    }
44
45 9
    public static function parseFile(string $file): mixed
46
    {
47 9
        return self::createParser()->parseFile($file);
48
    }
49
50
    public static function dump(mixed $var): mixed
51
    {
52
        return (new Dumper(
53
            Dumper::PRETTY_PRINT | Dumper::SHORT_SINGLE_ELEMENT
54
        ))->dump($var);
55
    }
56
}
57