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 ( 4017e5...2ab1f1 )
by Henrique
03:05
created

Equivalent::isStringEquivalent()   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
dl 0
loc 7
c 0
b 0
f 0
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 2
eloc 3
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 is_scalar;
17
use function mb_strtoupper;
18
19
/**
20
 * Validates if the input is equivalent to some value.
21
 *
22
 * @author Henrique Moody <[email protected]>
23
 */
24
final class Equivalent extends AbstractRule
25
{
26
    /**
27
     * @var mixed
28
     */
29
    private $compareTo;
30
31
    /**
32
     * Initializes the rule.
33
     *
34
     * @param mixed $compareTo
35
     */
36 1
    public function __construct($compareTo)
37
    {
38 1
        $this->compareTo = $compareTo;
39 1
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 10
    public function validate($input): bool
45
    {
46 10
        if (is_scalar($input)) {
47 5
            return $this->isStringEquivalent((string) $input);
48
        }
49
50 5
        return $input == $this->compareTo;
51
    }
52
53 5
    private function isStringEquivalent(string $input): bool
54
    {
55 5
        if (!is_scalar($this->compareTo)) {
56
            return false;
57
        }
58
59 5
        return mb_strtoupper((string) $input) === mb_strtoupper((string) $this->compareTo);
60
    }
61
}
62