GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

StrictScalarComparator::assertEquals()   C
last analyzed

Complexity

Conditions 12
Paths 27

Size

Total Lines 38
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
c 0
b 0
f 0
rs 5.1612
cc 12
eloc 22
nc 27
nop 5

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Isolate\UnitOfWork\Entity\Property\PHPUnitComparator;
4
5
use SebastianBergmann\Comparator\Comparator;
6
use SebastianBergmann\Comparator\ComparisonFailure;
7
8
class StrictScalarComparator extends Comparator
9
{
10
    /**
11
     * @param mixed $expected
12
     * @param mixed $actual
13
     * @return bool
14
     */
15
    public function accepts($expected, $actual)
16
    {
17
        return ((is_scalar($expected) xor null === $expected) &&
18
            (is_scalar($actual) xor null === $actual))
19
        // allow comparison between strings and objects featuring __toString()
20
        || (is_string($expected) && is_object($actual) && method_exists($actual, '__toString'))
21
        || (is_object($expected) && method_exists($expected, '__toString') && is_string($actual));
22
    }
23
24
    /**
25
     * @param mixed $expected
26
     * @param mixed $actual
27
     * @param float $delta
28
     * @param bool|false $canonicalize
29
     * @param bool|false $ignoreCase
30
     * @throws ComparisonFailure
31
     */
32
    public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false)
33
    {
34
        $expectedToCompare = $expected;
35
        $actualToCompare   = $actual;
36
37
        // always compare as strings to avoid strange behaviour
38
        // otherwise 0 == 'Foobar'
39
        if (is_string($expected) || is_string($actual)) {
40
            $expectedToCompare = (string) $expectedToCompare;
41
            $actualToCompare   = (string) $actualToCompare;
42
43
            if ($ignoreCase) {
44
                $expectedToCompare = strtolower($expectedToCompare);
45
                $actualToCompare   = strtolower($actualToCompare);
46
            }
47
        }
48
49
        if (is_null($expectedToCompare) && !is_bool($actual) || is_null($actual) && !is_bool($expectedToCompare)) {
50
            if ($expected !== $actual) {
51
                $this->throwComparisonFailureException($expected, $actual);
52
            }
53
        }
54
55
        if ($expectedToCompare != $actualToCompare) {
56
            if (is_string($expected) && is_string($actual)) {
57
                throw new ComparisonFailure(
58
                    $expected,
59
                    $actual,
60
                    $this->exporter->export($expected),
61
                    $this->exporter->export($actual),
62
                    false,
63
                    'Failed asserting that two strings are equal.'
64
                );
65
            }
66
67
            $this->throwComparisonFailureException($expected, $actual);
68
        }
69
    }
70
71
    /**
72
     * @param $expected
73
     * @param $actual
74
     */
75
    private function throwComparisonFailureException($expected, $actual)
76
    {
77
        throw new ComparisonFailure(
78
            $expected,
79
            $actual,
80
            $this->exporter->export($expected),
81
            $this->exporter->export($actual),
82
            false,
83
            sprintf(
84
                'Failed asserting that %s matches expected %s.',
85
                $this->exporter->export($actual),
86
                $this->exporter->export($expected)
87
            )
88
        );
89
    }
90
}
91