MaxItemsRule::message()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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