RegexpRule   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 32
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A validate() 0 3 1
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 string by regular expression
16
 *
17
 * @package Bluz\Validator\Rule
18
 */
19
class RegexpRule extends AbstractRule
20
{
21
    /**
22
     * @var string error template
23
     */
24
    protected $description = 'must validate with regular expression rule';
25
26
    /**
27
     * @var string regular expression for check string
28
     */
29
    protected $regexp;
30
31
    /**
32
     * Check string by regular expression
33
     *
34
     * @param string $regexp
35
     */
36 5
    public function __construct(string $regexp)
37
    {
38 5
        $this->regexp = $regexp;
39 5
    }
40
41
    /**
42
     * Check string by regular expression
43
     *
44
     * @param  mixed $input
45
     *
46
     * @return bool
47
     */
48 4
    public function validate($input): bool
49
    {
50 4
        return (bool)preg_match($this->regexp, $input);
51
    }
52
}
53