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

Passed
Pull Request — master (#957)
by Henrique
02:12
created

ComparisonHelper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 23
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B toComparable() 0 14 7
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 DateTimeImmutable;
17
use DateTimeInterface;
18
use Exception;
19
use function is_numeric;
20
use function is_string;
21
use function mb_strlen;
22
23
/**
24
 * Helps to deal with comparable values.
25
 *
26
 * @author Henrique Moody <[email protected]>
27
 */
28
trait ComparisonHelper
29
{
30
    /**
31
     * Tries to convert a value into something that can be compared with PHP operators.
32
     *
33
     * @param mixed $value
34
     *
35
     * @return mixed
36
     */
37
    private function toComparable($value)
38
    {
39
        if ($value instanceof DateTimeInterface || !is_string($value) || is_numeric($value) || empty($value)) {
40
            return $value;
41
        }
42
43
        if (1 === mb_strlen($value)) {
44
            return $value;
45
        }
46
47
        try {
48
            return new DateTimeImmutable($value);
49
        } catch (Exception $e) {
50
            return $value;
51
        }
52
    }
53
}
54