Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#1176)
by Henrique
02:49
created

Regex   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 5
dl 0
loc 27
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 7 2
A __construct() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of Respect/Validation.
5
 *
6
 * (c) Alexandre Gomes Gaigalas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the "LICENSE.md"
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
use function is_scalar;
17
use function preg_match;
18
19
/**
20
 * Validates whether the input matches a defined regular expression.
21
 *
22
 * @author Alexandre Gomes Gaigalas <[email protected]>
23
 * @author Danilo Correa <[email protected]>
24
 * @author Henrique Moody <[email protected]>
25
 */
26
final class Regex extends AbstractRule
27
{
28
    /**
29
     * @var string
30
     */
31
    private $regex;
32
33
    /**
34
     * Initializes the rule.
35
     *
36
     * @param string $regex
37
     */
38 1
    public function __construct(string $regex)
39
    {
40 1
        $this->regex = $regex;
41 1
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 7
    public function validate($input): bool
47
    {
48 7
        if (!is_scalar($input)) {
49 3
            return false;
50
        }
51
52 5
        return preg_match($this->regex, (string) $input) > 0;
53
    }
54
}
55