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

RuleMapping   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 4
lcom 2
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 8 2
A getRule() 0 12 2
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
}