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 ( 410658...03ea1b )
by Henrique
03:11
created

Isbn::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0625
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 implode;
17
use function is_scalar;
18
use function preg_match;
19
use function sprintf;
20
21
/**
22
 * Validates whether the input is a valid ISBN (International Standard Book Number) or not.
23
 *
24
 * @author Henrique Moody <[email protected]>
25
 * @author Moritz Fromm <[email protected]>
26
 */
27
final class Isbn extends AbstractRule
28
{
29
    /**
30
     * @see https://howtodoinjava.com/regex/java-regex-validate-international-standard-book-number-isbns
31
     */
32
    private const PIECES = [
33
        '^(?:ISBN(?:-1[03])?:? )?(?=[0-9X]{10}$|(?=(?:[0-9]+[- ]){3})',
34
        '[- 0-9X]{13}$|97[89][0-9]{10}$|(?=(?:[0-9]+[- ]){4})[- 0-9]{17}$)',
35
        '(?:97[89][- ]?)?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]$',
36
    ];
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 18
    public function validate($input): bool
42
    {
43 18
        if (!is_scalar($input)) {
44
            return false;
45
        }
46
47 18
        return preg_match(sprintf('/%s/', implode(self::PIECES)), $input) > 0;
48
    }
49
}
50