Passed
Push — master ( 439fe5...0de0cb )
by
unknown
01:42
created

Rule::getStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: harry
5
 * Date: 2/15/18
6
 * Time: 5:05 PM
7
 */
8
9
namespace PluginSimpleValidate;
10
11
use PluginSimpleValidate\Libraries\Language;
12
13
class Rule implements \PluginSimpleValidate\Contracts\Rule
14
{
15
    /**
16
     * @var string
17
     */
18
    private $validationMethod;
19
20
    /**
21
     * @var string
22
     */
23
    private $langKey;
24
25
    /**
26
     * @var bool
27
     */
28
    private $status;
29
30
    /**
31
     * @var string
32
     */
33
    private $error;
34
35 3
    public function __construct(string $validationMethod, string $langKey)
36
    {
37 3
        $this->validationMethod = $validationMethod;
38 3
        $this->langKey = $langKey;
39 3
        $this->status = false;
40 3
        $this->error = '';
41 3
    }
42
43
    /**
44
     * @return string
45
     */
46 3
    public function getValidationMethod(): string
47
    {
48 3
        return $this->validationMethod;
49
    }
50
51
    /**
52
     * @return string
53
     */
54 3
    public function getLangKey(): string
55
    {
56 3
        return $this->langKey;
57
    }
58
59
    /**
60
     * @return bool
61
     */
62
    public function getStatus(): bool
63
    {
64
        return $this->status;
65
    }
66
67
    /**
68
     * @param Language $language
69
     * @param $value
70
     * @return bool
71
     */
72 3
    public function isValid(Language $language, $value) : bool
73
    {
74 3
        if (!call_user_func_array(
75 3
            '\\PluginSimpleValidate\\helper\\Validate\\' . $this->getValidationMethod(),
76
            [
77 3
                $value
78
            ]
79
        )) {
80 3
            $this->status = false;
81
82 3
            $this->error = $language->getTranslation(
0 ignored issues
show
Documentation Bug introduced by
It seems like $language->getTranslation($this->getLangKey()) can also be of type array. However, the property $error is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
83 3
                $this->getLangKey()
84
            );
85
        } else {
86
            $this->status = true;
87
        }
88
89 3
        return $this->status;
90
    }
91
}