Completed
Pull Request — master (#430)
by Anton
04:09 queued 58s
created

VersionRule::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
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 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
    public function validate($input): bool
34
    {
35
        $pattern = '/^[0-9]+\.[0-9]+\.[0-9]+([+-][^+-][0-9A-Za-z-.]*)?$/';
36
37
        return (bool)preg_match($pattern, $input);
38
    }
39
}
40