SlugRule   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 29
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 15 4
1
<?php
2
3
/**
4
 * Bluz Framework Component
5
 *
6
 * @copyright Bluz PHP Team
7
 * @link      https://github.com/bluzphp/framework
8
 */
9
10
declare(strict_types=1);
11
12
namespace Bluz\Validator\Rule;
13
14
/**
15
 * Check for slug by regular expressions
16
 *
17
 * @package Bluz\Validator\Rule
18
 */
19
class SlugRule extends AbstractRule
20
{
21
    /**
22
     * @var string error template
23
     */
24
    protected $description = 'must be a valid slug';
25
26
    /**
27
     * Check input data
28
     *
29
     * @param  string $input
30
     *
31
     * @return bool
32
     */
33 14
    public function validate($input): bool
34
    {
35 14
        if (false !== strpos($input, '--')) {
36 2
            return false;
37
        }
38
39 12
        if (!preg_match('/^[0-9a-z\-]+$/', $input)) {
40 6
            return false;
41
        }
42
43 6
        if (preg_match('/^-|-$/', $input)) {
44 2
            return false;
45
        }
46
47 4
        return true;
48
    }
49
}
50