Completed
Push — master ( 4d3c9c...4a4bf4 )
by Gerrit
02:32
created

expectedDifferentService()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 38
Code Lines 25

Duplication

Lines 12
Ratio 31.58 %

Code Coverage

Tests 17
CRAP Score 3.0015

Importance

Changes 0
Metric Value
dl 12
loc 38
ccs 17
cts 18
cp 0.9444
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 25
nc 4
nop 4
crap 3.0015
1
<?php
2
/**
3
 * Copyright (C) 2018 Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks\RDMBundle\Exception;
12
13
use ErrorException;
14
use ReflectionClass;
15
use Addiks\RDMBundle\Exception\FailedRDMAssertionExceptionInterface;
16
17
final class FailedRDMAssertionException extends ErrorException implements FailedRDMAssertionExceptionInterface
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: __toString, getCode, getFile, getLine, getMessage, getPrevious, getTrace, getTraceAsString
Loading history...
18
{
19
20
    /**
21
     * @var string
22
     */
23
    private $type;
24
25
    /**
26
     * @var array<mixed>
27
     */
28
    private $parameters;
29
30 2
    public function __construct(string $message, string $type, array $parameters)
31
    {
32 2
        parent::__construct($message);
33
34 2
        $this->type = $type;
35 2
        $this->parameters = $parameters;
36 2
    }
37
38
    public function getType(): string
39
    {
40
        return $this->type;
41
    }
42
43
    public function getParameters(): array
44
    {
45
        return $this->parameters;
46
    }
47
48
    /**
49
     * @param mixed $expectedService
50
     * @param mixed $actualService
51
     */
52 2
    public static function expectedDifferentService(
53
        string $serviceId,
54
        ReflectionClass $classReflection,
55
        $expectedService,
56
        $actualService
57
    ): FailedRDMAssertionException {
58
        /** @var string $actualDescription */
59 2
        $actualDescription = null;
0 ignored issues
show
Unused Code introduced by
$actualDescription is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
60
61 2 View Code Duplication
        if (is_object($actualService)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62 1
            $actualDescription = get_class($actualService) . '#' . spl_object_hash($actualService);
63
64
        } else {
65 1
            $actualDescription = gettype($actualService);
66
        }
67
68
        /** @var string $expectedDescription */
69 2
        $expectedDescription = null;
0 ignored issues
show
Unused Code introduced by
$expectedDescription is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
70
71 2 View Code Duplication
        if (is_object($expectedService)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72 2
            $expectedDescription = get_class($expectedService) . '#' . spl_object_hash($expectedService);
73
74
        } else {
75
            $expectedDescription = gettype($expectedService);
76
        }
77
78 2
        return new self(
79 2
            sprintf(
80 2
                "Expected service %s (%s) on entity %s, was %s instead!",
81 2
                $serviceId,
82 2
                $expectedDescription,
83 2
                $classReflection->getName(),
0 ignored issues
show
Bug introduced by
Consider using $classReflection->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
84 2
                $actualDescription
85
            ),
86 2
            "EXPECTED_DIFFERENT_SERVICE",
87 2
            [$serviceId, $expectedService, $actualService]
88
        );
89
    }
90
91
}
92