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 (#1001)
by Henrique
02:21
created

Base   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 39
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A validate() 0 5 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 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