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.

IsEqual::handleResult()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
ccs 5
cts 5
cp 1
rs 8.9713
cc 3
eloc 15
nc 3
nop 5
crap 3
1
<?php
2
3
/**
4
 * @license https://github.com/f500/equatable/blob/master/LICENSE MIT
5
 */
6
7
declare(strict_types=1);
8
9
namespace F500\Equatable\PHPUnit\Constraint;
10
11
use F500\Equatable\Equatable;
12
use PHPUnit\Framework\Constraint\IsEqual as BaseIsEqual;
13
use PHPUnit\Framework\ExpectationFailedException;
14
use SebastianBergmann\Comparator\ComparisonFailure;
15
16
/**
17
 * @copyright Copyright (c) 2015 Future500 B.V.
18
 * @author    Jasper N. Brouwer <[email protected]>
19
 */
20
final class IsEqual extends BaseIsEqual
21
{
22
    /**
23
     * @var mixed
24
     */
25 21
    private $value;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
26
27 21
    /**
28 3
     * @inheritdoc
29
     */
30
    public function __construct($value, float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
31 18
    {
32 9
        parent::__construct($value, $delta, $maxDepth, $canonicalize, $ignoreCase);
33 9
34 9
        $this->value = $value;
35 9
    }
36 9
37 9
    /**
38
     * @inheritdoc
39
     */
40
    public function evaluate($other, $description = '', $returnResult = false)
41 9
    {
42 6
        if ($this->value === $other) {
43 6
            return true;
44 6
        }
45 6
46 6
        if ($this->value instanceof Equatable) {
47 6
            return $this->handleResult(
48
                $this->value,
49
                $other,
50
                $this->value->equals($other),
51 3
                $description,
52
                $returnResult
53
            );
54
        }
55
56
        if ($other instanceof Equatable) {
57
            return $this->handleResult(
58
                $this->value,
59
                $other,
60
                $other->equals($this->value),
61
                $description,
62
                $returnResult
63 15
            );
64
        }
65 15
66 3
        return parent::evaluate($other, $description, $returnResult);
67
    }
68
69 12
    /**
70 6
     * @param mixed  $expected
71
     * @param mixed  $actual
72
     * @param bool   $result
73 6
     * @param string $description
74 6
     * @param bool   $returnResult
75 6
     *
76 6
     * @return bool
77 6
     */
78 6
    private function handleResult($expected, $actual, $result, $description, $returnResult)
79 6
    {
80
        if ($result) {
81
            return true;
82 6
        }
83 6
84 6
        if ($returnResult) {
85
            return false;
86
        }
87
88
        $comparisonFailure = new ComparisonFailure(
89
            $expected,
90
            $actual,
91
            $this->exporter->export($expected),
92
            $this->exporter->export($actual),
93
            false,
94
            'Failed asserting that two equatable objects are equal.'
95
        );
96
97
        throw new ExpectationFailedException(
98
            trim($description . "\n" . $comparisonFailure->getMessage()),
99
            $comparisonFailure
100
        );
101
    }
102
}
103