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 (#1082)
by Henrique
04:13
created

ComparisonHelper   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
eloc 11
dl 0
loc 41
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isAbleToCompareValues() 0 3 1
B toComparable() 0 18 8
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 102
    private function toComparable($value)
39
    {
40 102
        if ($value instanceof Countable) {
41 10
            return $value->count();
42
        }
43
44 102
        if ($value instanceof DateTimeInterface || !is_string($value) || is_numeric($value) || empty($value)) {
45 72
            return $value;
46
        }
47
48 48
        if (1 === mb_strlen($value)) {
49 18
            return $value;
50
        }
51
52
        try {
53 35
            return new DateTimeImmutable($value);
54 3
        } catch (Exception $e) {
55 3
            return $value;
56
        }
57
    }
58
59
    /**
60
     * Returns whether the values can be compared or not.
61
     *
62
     * @param mixed $left
63
     * @param mixed $right
64
     *
65
     * @return bool
66
     */
67 100
    private function isAbleToCompareValues($left, $right)
68
    {
69 100
        return is_scalar($left) === is_scalar($right);
70
    }
71
}
72