Passed
Push — feature/job-builder/step-01 ( a153c5...990c2a )
by Tristan
15:40 queued 09:50
created

ValidIdRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 40
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A passes() 0 4 1
A message() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace App\Services\Validation\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Support\Facades\Lang;
7
8
class ValidIdRule implements Rule
9
{
10
    /**
11
     * The fully qualified classname of the model to check.
12
     *
13
     * @var string
14
     */
15
    protected $className;
16
17
    /**
18
     * Create a rule that tests that a value is a valid id for the specified eloquent model.
19
     *
20
     * @param string $className
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
21
     */
22 5
    public function __construct(string $className)
23
    {
24 5
        $this->className = $className;
25 5
    }
26
27
    /**
28
     * Determine if the validation rule passes.
29
     *
30
     * @param  string  $attribute
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
31
     * @param  mixed  $value
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
32
     * @return bool
1 ignored issue
show
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
33
     */
34 5
    public function passes($attribute, $value)
1 ignored issue
show
introduced by
Method \App\Services\Validation\Rules\ValidIdRule::passes() does not have parameter type hint for its parameter $attribute but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \App\Services\Validation\Rules\ValidIdRule::passes() does not have return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
Coding Style introduced by
Type hint "string" missing for $attribute
Loading history...
35
    {
36 5
        $model = $this->className;
37 5
        return $model::where('id', $value)->exists();
38
    }
39
40
    /**
41
     * Get the validation error message.
42
     *
43
     * @return string
44
     */
45 1
    public function message()
0 ignored issues
show
introduced by
Method \App\Services\Validation\Rules\ValidIdRule::message() does not have return type hint for its return value but it should be possible to add it based on @return annotation "string".
Loading history...
46
    {
47 1
        return Lang::get('validation.invalid_id');
0 ignored issues
show
Bug Best Practice introduced by
The expression return Illuminate\Suppor...validation.invalid_id') also could return the type array which is incompatible with the documented return type string.
Loading history...
48
    }
49
}
50