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

RegexpRule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 4 1
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
    public function __construct($regexp)
36
    {
37
        $this->regexp = $regexp;
38
    }
39
40
    /**
41
     * Check string by regular expression
42
     *
43
     * @param  mixed $input
44
     *
45
     * @return bool
46
     */
47
    public function validate($input): bool
48
    {
49
        return (bool)preg_match($this->regexp, $input);
50
    }
51
}
52