Completed
Push — master ( 32a72a...87f4e4 )
by Freek
22:12 queued 07:19
created

ModelIds   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 26
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A passes() 0 10 1
A message() 0 4 1
1
<?php
2
3
namespace Spatie\ValidationRules\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
7
class ModelIds implements Rule
8
{
9
    /** @var string */
10
    protected $modelClassName;
11
12
    public function __construct(string $modelClassName)
13
    {
14
        $this->modelClassName = $modelClassName;
15
    }
16
17
    public function passes($attribute, $value)
18
    {
19
        $value = array_filter($value);
20
21
        $modelIds = array_unique($value);
22
23
        $modelCount = $this->modelClassName::whereIn('id', $modelIds)->count();
0 ignored issues
show
Bug introduced by
The method whereIn cannot be called on $this->modelClassName (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
24
25
        return count($modelIds) === $modelCount;
26
    }
27
28
    public function message()
29
    {
30
        return __('validationRules.model_ids');
31
    }
32
}
33