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

ModelIds::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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