MaxItemsRule   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 15
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A message() 0 4 1
A passes() 0 3 2
A __construct() 0 2 1
1
<?php
2
3
namespace Spatie\MediaLibraryPro\Rules\GroupRules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
7
class MaxItemsRule implements Rule
8
{
9
    public function __construct(protected int $maxItemCount)
10
    {
11
    }
12
13
    public function passes($attribute, $value)
14
    {
15
        return (is_countable($value) ? count($value) : 0) <= $this->maxItemCount;
16
    }
17
18
    public function message()
19
    {
20
        return trans_choice('media-library::validation.max_items', $this->maxItemCount, [
21
            'max' => $this->maxItemCount,
22
        ]);
23
    }
24
}
25