AbstractValidationRule::getValidationRule()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/*
4
 * This file is part of persian validation package
5
 *
6
 * (c) Farhad Zand <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Iamfarhad\Validation\Contracts;
13
14
abstract class AbstractValidationRule
15
{
16
    /**
17
     * @var null
18
     */
19
    public $validationRule;
20
21
    /**
22
     * @param $attribute
23
     * @param $value
24
     * @param $parameters
25
     * @param $validator
26
     * @return bool
27
     */
28
    abstract public function rule($attribute, $value, $parameters, $validator): bool;
29
30
    /**
31
     * Set validation Rule name.
32
     *
33
     * @param  string  $name
34
     */
35
    public function setValidationRule(string $name): void
36
    {
37
        $this->validationRule = $name;
0 ignored issues
show
Documentation Bug introduced by
It seems like $name of type string is incompatible with the declared type null of property $validationRule.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38
    }
39
40
    /**
41
     * Get validation Rule name.
42
     *
43
     * @return string
44
     */
45
    public function getValidationRule(): string
46
    {
47
        return $this->validationRule;
48
    }
49
50
    /**
51
     * Register laravel validation extension.
52
     */
53
    public function register(): void
54
    {
55
        \Validator::extend($this->getValidationRule(), function ($attribute, $value, $parameters, $validator) {
56
            return $this->rule($attribute, $value, $parameters, $validator);
57
        });
58
        \Validator::replacer($this->getValidationRule(), 'ValidationMessages@message');
59
    }
60
}
61