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 (#973)
by Emmerson
03:07
created

ComparisonHelper::toComparable()   B

Complexity

Conditions 8
Paths 5

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 8.064

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 10
cp 0.9
rs 7.7777
c 0
b 0
f 0
cc 8
eloc 10
nc 5
nop 1
crap 8.064
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\Helpers;
15
16
use Countable;
17
use DateTimeImmutable;
18
use DateTimeInterface;
19
use Exception;
20
use function is_numeric;
21
use function is_string;
22
use function mb_strlen;
23
24
/**
25
 * Helps to deal with comparable values.
26
 *
27
 * @author Henrique Moody <[email protected]>
28
 */
29
trait ComparisonHelper
30
{
31
    /**
32
     * Tries to convert a value into something that can be compared with PHP operators.
33
     *
34
     * @param mixed $value
35
     *
36
     * @return mixed
37
     */
38 12
    private function toComparable($value)
39
    {
40 12
        if ($value instanceof Countable) {
41
            return $value->count();
42
        }
43
44 12
        if ($value instanceof DateTimeInterface || !is_string($value) || is_numeric($value) || empty($value)) {
45 10
            return $value;
46
        }
47
48 9
        if (1 === mb_strlen($value)) {
49 6
            return $value;
50
        }
51
52
        try {
53 8
            return new DateTimeImmutable($value);
54 2
        } catch (Exception $e) {
55 2
            return $value;
56
        }
57
    }
58
}
59