Completed
Push — master ( 121fac...aa6513 )
by Harry Osmar
06:34 queued 03:36
created

RuleMapping::getRule()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 12
ccs 6
cts 7
cp 0.8571
crap 2.0116
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: harry
5
 * Date: 2/15/18
6
 * Time: 4:51 PM
7
 */
8
9
namespace PluginSimpleValidate\Libraries;
10
11
use PluginSimpleValidate\Exception\RuleNotExist;
12
use PluginSimpleValidate\Rule;
13
14
class RuleMapping extends \PluginSimpleValidate\BaseAbstract\RuleMapping
15
{
16
    /**
17
     * @return \PluginSimpleValidate\Contracts\RuleMapping
18
     */
19 9
    public static function getInstance()
20
    {
21 9
        if (is_null(static::$instance)) {
22 1
            static::$instance = new self();
23
        }
24
25 9
        return static::$instance;
26
    }
27
28
    /**
29
     * @param string $key
30
     * @param array $args
31
     * @return \PluginSimpleValidate\Contracts\Rule
32
     * @throws RuleNotExist
33
     */
34 9
    public function getRule(string $key, array $args = []) : \PluginSimpleValidate\Contracts\Rule
35
    {
36 9
        if (!isset($this->list[$key])) {
37
            throw new RuleNotExist('Rule does not exist');
38
        }
39
40 9
        return new Rule(
41 9
            $this->list[$key]['validation_method'],
42 9
            $this->list[$key]['lang_key'],
43 9
            $args
44
        );
45
    }
46
}