ValidDuplicateCharacter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A message() 0 3 1
A passes() 0 5 1
1
<?php
2
3
namespace Milwad\LaravelValidate\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
7
class ValidDuplicateCharacter implements Rule
8
{
9
    /**
10
     * Check duplicate characters, splitted by comma.
11
     */
12
    public function passes($attribute, $value): bool
13
    {
14
        $value = explode(',', $value);
15
16
        return collect($value)->duplicates()->isEmpty();
0 ignored issues
show
Bug introduced by
$value of type string[] is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

16
        return collect(/** @scrutinizer ignore-type */ $value)->duplicates()->isEmpty();
Loading history...
17
    }
18
19
    /**
20
     * Get the validation error message.
21
     */
22
    public function message(): string
23
    {
24
        return __('validate.duplicate_character');
25
    }
26
}
27