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
Push — master ( 35a43c...68b3f2 )
by Henrique
02:35
created

Base::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
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 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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 Respect\Validation\Exceptions\ComponentException;
17
use function is_null;
18
use function mb_strlen;
19
use function preg_match;
20
use function sprintf;
21
22
/**
23
 * Validate numbers in any base, even with non regular bases.
24
 *
25
 * @author Carlos André Ferrari <[email protected]>
26
 * @author Henrique Moody <[email protected]>
27
 * @author William Espindola <[email protected]>
28
 */
29
final class Base extends AbstractRule
30
{
31
    /**
32
     * @var string
33
     */
34
    private $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
35
36
    /**
37
     * @var int
38
     */
39
    private $base;
40
41
    /**
42
     * Initializes the Base rule.
43
     *
44
     * @param int $base
45
     * @param string $chars
46
     */
47 1
    public function __construct(int $base, $chars = null)
48
    {
49 1
        if (!is_null($chars)) {
50
            $this->chars = $chars;
51
        }
52
53 1
        $max = mb_strlen($this->chars);
54 1
        if ($base > $max) {
55
            throw new ComponentException(sprintf('a base between 1 and %s is required', $max));
56
        }
57 1
        $this->base = $base;
58 1
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 24
    public function validate($input): bool
64
    {
65 24
        $valid = mb_substr($this->chars, 0, $this->base);
66
67 24
        return (bool) preg_match("@^[$valid]+$@", (string) $input);
68
    }
69
}
70