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

RuleLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 25
ccs 7
cts 8
cp 0.875
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A load_rules_from() 0 7 2
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