Completed
Push — master ( cc2765...340ff8 )
by Richard
08:19
created

RuleLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/******************************************************************************
3
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
4
 *
5
 * Copyright (c) 2016, 2015 Richard Klees <[email protected]>
6
 *
7
 * This software is licensed under The MIT License. You should have received
8
 * a copy of the license along with the code.
9
 */
10
11
namespace Lechimp\Dicto\App;
12
13
use Lechimp\Dicto\Rule\Ruleset;
14
use Lechimp\Dicto\Definition\RuleParser;
15
use Lechimp\Dicto\Definition\ParserException;
16
17
class RuleLoader {
18
    /**
19
     * @var RuleParser
20
     */
21
    protected $parser;
22
23 4
    public function __construct(RuleParser $parser) {
24 4
        $this->parser = $parser;
25 4
    }
26
27
    /**
28
     * Load rules from file at given path.
29
     *
30
     * @param   string  $rule_file_path
31
     * @throws  ParserException if file can't be parsed.
32
     * @return  Ruleset
33
     */
34 4
    public function load_rules_from($rule_file_path) {
35 4
        if (!file_exists($rule_file_path)) {
36
            throw new \InvalidArgumentException("$rule_file_path does not exist.");
37
        }
38 4
        $content = file_get_contents($rule_file_path);
39 4
        return $this->parser->parse($content);
40
    }
41
}
42