Completed
Push — develop ( f4bf89...9fcb81 )
by Ludwig
02:21
created

RuleFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRules() 0 14 4
1
<?php
2
/*
3
 * This file is part of Bounce-Detection.
4
 *
5
 * (c)2016 cwd.at GmbH <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Cwd\BounceDetection;
11
12
use Symfony\Component\Yaml\Yaml;
13
14
/**
15
 * Class RuleFactory
16
 *
17
 * @package Cwd\BounceDetection
18
 * @author  Ludwig Ruderstaller <[email protected]>
19
 */
20
class RuleFactory
21
{
22
    const RULE_FILE = 'rules.yml';
23
24
    /**
25
     * @param null|string $ruleFile
26
     *
27
     * @return RuleConfig
28
     * @throws \Exception
29
     */
30 2
    public static function getRules($ruleFile = null)
31
    {
32 2
        if ($ruleFile === null) {
33 1
            $ruleFile = __DIR__.'/'.self::RULE_FILE;
34 1
        }
35
36 2
        if (!file_exists($ruleFile) || !is_readable($ruleFile)) {
37 1
            throw new \Exception(sprintf('Rule file %s is not found or not readable', $ruleFile));
38
        }
39
40 1
        $rules = Yaml::parse(file_get_contents($ruleFile));
41
42 1
        return new RuleConfig($rules);
43
    }
44
}
45