Passed
Push — master ( 651556...010605 )
by Pierrick
10:35
created

Nacl   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 78.95%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 37
ccs 15
cts 19
cp 0.7895
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A registerMacro() 0 3 1
A dump() 0 5 1
A createParser() 0 11 2
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
namespace Nuglif\Nacl;
15
16
class Nacl
17
{
18
    private static $macros = [];
19
20 1
    public static function registerMacro(MacroInterface $macro)
21
    {
22 1
        self::$macros[] = $macro;
23 1
    }
24
25 577
    public static function createParser()
26
    {
27 577
        $parser = new Parser;
28 577
        $parser->registerMacro(new Macros\Env);
29 577
        $parser->registerMacro(new Macros\Constant);
30
31 577
        foreach (self::$macros as $macro) {
32 5
            $parser->registerMacro($macro);
33 577
        }
34
35 577
        return $parser;
36
    }
37
38 538
    public static function parse($str)
39
    {
40 538
        return self::createParser()->parse($str);
41
    }
42
43 9
    public static function parseFile($file)
44
    {
45 9
        return self::createParser()->parseFile($file);
46
    }
47
48
    public static function dump($var)
49
    {
50
        return (new Dumper(
51
            Dumper::PRETTY_PRINT | Dumper::SHORT_SINGLE_ELEMENT
52
        ))->dump($var);
53
    }
54
}
55