Completed
Pull Request — master (#430)
by Anton
04:30
created

RegexpRule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Validator\Rule;
12
13
/**
14
 * Check string by regular expression
15
 *
16
 * @package Bluz\Validator\Rule
17
 */
18
class RegexpRule extends AbstractRule
19
{
20
    /**
21
     * @var string error template
22
     */
23
    protected $description = 'must validate with regular expression rule';
24
25
    /**
26
     * @var string regular expression for check string
27
     */
28
    protected $regexp;
29
30
    /**
31
     * Check string by regular expression
32
     *
33
     * @param string $regexp
34
     */
35 4
    public function __construct($regexp)
36
    {
37 4
        $this->regexp = $regexp;
38 4
    }
39
40
    /**
41
     * Check string by regular expression
42
     *
43
     * @param  mixed $input
44
     *
45
     * @return bool
46
     */
47 4
    public function validate($input): bool
48
    {
49 4
        return (bool)preg_match($this->regexp, $input);
50
    }
51
}
52