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

Nacl   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 76.47%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 37
ccs 13
cts 17
cp 0.7647
rs 10
c 1
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A dump() 0 5 1
A createParser() 0 11 2
A registerMacro() 0 3 1
A parseFile() 0 3 1
A parse() 0 3 1
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