LaravelValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php namespace Salah3id\Domains\Validator;
2
3
use Illuminate\Contracts\Validation\Factory;
4
5
/**
6
 * Class LaravelValidator
7
 * @package Salah3id\Domains\Validator
8
 * @author Anderson Andrade <[email protected]>
9
 */
10
class LaravelValidator extends AbstractValidator
11
{
12
    /**
13
     * Validator
14
     *
15
     * @var \Illuminate\Validation\Factory
16
     */
17
    protected $validator;
18
19
    /**
20
     * Construct
21
     *
22
     * @param \Illuminate\Contracts\Validation\Factory $validator
23
     */
24
    public function __construct(Factory $validator)
25
    {
26
        $this->validator = $validator;
0 ignored issues
show
Documentation Bug introduced by
$validator is of type Illuminate\Contracts\Validation\Factory, but the property $validator was declared to be of type Illuminate\Validation\Factory. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
27
    }
28
29
    /**
30
     * Pass the data and the rules to the validator
31
     *
32
     * @param string $action
33
     * @return bool
34
     */
35
    public function passes($action = null)
36
    {
37
        $rules      = $this->getRules($action);
0 ignored issues
show
Bug introduced by
It seems like $action can also be of type string; however, parameter $action of Salah3id\Domains\Validat...ctValidator::getRules() does only seem to accept null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        $rules      = $this->getRules(/** @scrutinizer ignore-type */ $action);
Loading history...
38
        $messages   = $this->getMessages();
39
        $attributes = $this->getAttributes();
40
        $validator  = $this->validator->make($this->data, $rules, $messages, $attributes);
41
42
        if ($validator->fails()) {
43
            $this->errors = $validator->messages();
44
            return false;
45
        }
46
47
        return true;
48
    }
49
}
50