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 (#998)
by William
06:15 queued 04:02
created

Base::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.3731

Importance

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