RuleMapping::getRule()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 3
dl 11
loc 11
ccs 7
cts 7
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: harry
5
 * Date: 2/26/18
6
 * Time: 5:38 PM
7
 */
8
9
namespace PluginSimpleValidate\Libraries\MultiValues;
10
11
use PluginSimpleValidate\Contracts\RuleMappingWithValue;
12
use PluginSimpleValidate\Contracts\RuleWithValue as ContractsRuleWithValue;
13
use PluginSimpleValidate\Exception\RuleNotExist;
14
use PluginSimpleValidate\WithValue\Rule;
15
16 View Code Duplication
class RuleMapping extends \PluginSimpleValidate\BaseAbstract\RuleMapping implements RuleMappingWithValue
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    /**
19
     * @var $this
20
     */
21
    private static $instance;
22
23
    /**
24
     * @return \PluginSimpleValidate\Contracts\RuleMappingWithValue
25
     */
26 4
    public static function getInstance()
27
    {
28 4
        if (is_null(static::$instance)) {
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
29 1
            static::$instance = new self();
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
30
        }
31
32 4
        return static::$instance;
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
33
    }
34
35
    /**
36
     * @param string $key
37
     * @param mixed $value
38
     * @param array $args
39
     * @return ContractsRuleWithValue
40
     * @throws RuleNotExist
41
     */
42 4
    public function getRule(string $key, $value, array $args = []): ContractsRuleWithValue
43
    {
44 4
        $this->checkRule($key);
45
46 4
        return new Rule(
47 4
            $this->list[$key]['validation_method'],
48 4
            $this->list[$key]['lang_key'],
49 4
            $value,
50 4
            $args
51
        );
52
    }
53
}