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

VersionRule   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 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 for version format
15
 *
16
 * @package Bluz\Validator\Rule
17
 * @link    http://semver.org/
18
 */
19
class VersionRule extends AbstractRule
20
{
21
    /**
22
     * @var string error template
23
     */
24
    protected $description = 'must be a version';
25
26
    /**
27
     * Check for version format
28
     *
29
     * @param  string $input
30
     *
31
     * @return bool
32
     */
33 14
    public function validate($input): bool
34
    {
35 14
        $pattern = '/^[0-9]+\.[0-9]+\.[0-9]+([+-][^+-][0-9A-Za-z-.]*)?$/';
36
37 14
        return (bool)preg_match($pattern, $input);
38
    }
39
}
40