Slug   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A passes() 0 3 1
A message() 0 3 1
1
<?php
2
3
namespace SeedsStd\SlugValidation;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Support\Str;
7
8
class Slug implements Rule
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $configs;
14
15
    /**
16
     * Create a new rule instance.
17
     *
18
     * @param array $configs
19
     * @return void
20
     */
21
    public function __construct(array $configs = [])
22
    {
23
        $default_configs = [
24
            'separator' => '-',
25
            'language' => 'en',
26
        ];
27
28
        $this->configs = array_merge($default_configs, $configs);
29
    }
30
31
    /**
32
     * Determine if the validation rule passes.
33
     *
34
     * @param  string $attribute
35
     * @param  mixed $value
36
     * @return bool
37
     */
38
    public function passes($attribute, $value)
39
    {
40
        return $value === Str::slug($value, $this->configs['separator'], $this->configs['language']);
41
    }
42
43
    /**
44
     * Get the validation error message.
45
     *
46
     * @return string
47
     */
48
    public function message()
49
    {
50
        return __('validation.slug');
0 ignored issues
show
Bug Best Practice introduced by
The expression return __('validation.slug') also could return the type array which is incompatible with the documented return type string.
Loading history...
51
    }
52
}
53