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.

EquatableAssertionCapabilities   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 180
Duplicated Lines 26.67 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 17
c 2
b 0
f 0
lcom 1
cbo 6
dl 48
loc 180
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A assertEquals() 0 13 1
A assertNotEquals() 0 15 1
B assertContains() 22 22 6
B assertNotContains() 26 26 6
A equalTo() 0 15 1
A attributeEqualTo() 0 13 1
A contains() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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;
10
11
use F500\Equatable\PHPUnit\Constraint\EquatableCollectionContains;
12
use F500\Equatable\PHPUnit\Constraint\IsEqual;
13
use PHPUnit\Framework\Constraint\IsEqual as PHPUnitIsEqual;
14
use PHPUnit\Framework\Constraint\TraversableContains as PHPUnitTraversableContains;
15
use PHPUnit\Framework\Assert;
16
use PHPUnit\Framework\Constraint\Attribute;
17
use PHPUnit\Framework\Constraint\LogicalNot;
18
use PHPUnit\Framework\Constraint\StringContains;
19
use PHPUnit\Util\InvalidArgumentHelper;
20
21
/**
22
 * @copyright Copyright (c) 2015 Future500 B.V.
23
 * @author    Jasper N. Brouwer <[email protected]>
24
 */
25
trait EquatableAssertionCapabilities
26
{
27
    /**
28
     * @param mixed  $expected
29
     * @param mixed  $actual
30
     * @param string $message
31
     * @param float  $delta
32
     * @param int    $maxDepth
33
     * @param bool   $canonicalize
34
     * @param bool   $ignoreCase
35
     */
36
    public static function assertEquals(
37
        $expected,
38
        $actual,
39
        string $message = '',
40
        float $delta = 0.0,
41
        int $maxDepth = 10,
42
        bool $canonicalize = false,
43
        bool $ignoreCase = false
44
    ): void {
45
        $constraint = self::equalTo($expected, $delta, $maxDepth, $canonicalize, $ignoreCase);
46
47
        Assert::assertThat($actual, $constraint, $message);
48
    }
49
50
    /**
51
     * @param mixed  $expected
52
     * @param mixed  $actual
53
     * @param string $message
54
     * @param float  $delta
55
     * @param int    $maxDepth
56
     * @param bool   $canonicalize
57
     * @param bool   $ignoreCase
58
     */
59
    public static function assertNotEquals(
60
        $expected,
61
        $actual,
62
        string $message = '',
63
        $delta = 0.0,
64
        $maxDepth = 10,
65
        $canonicalize = false,
66
        $ignoreCase = false
67
    ): void {
68
        $constraint = new LogicalNot(
69
            self::equalTo($expected, $delta, $maxDepth, $canonicalize, $ignoreCase)
70
        );
71
72
        Assert::assertThat($actual, $constraint, $message);
73
    }
74
75
    /**
76
     * @param mixed  $needle
77
     * @param mixed  $haystack
78
     * @param string $message
79
     * @param bool   $ignoreCase
80
     * @param bool   $checkForObjectIdentity
81
     * @param bool   $checkForNonObjectIdentity
82
     */
83 View Code Duplication
    public static function assertContains(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
84
        $needle,
85
        $haystack,
86
        string $message = '',
87
        bool $ignoreCase = false,
88
        bool $checkForObjectIdentity = true,
89
        bool $checkForNonObjectIdentity = false
90
    ): void {
91
        if (is_array($haystack) || is_object($haystack) && $haystack instanceof \Traversable) {
92
            $constraint = self::contains($needle, $checkForObjectIdentity, $checkForNonObjectIdentity);
93
        } elseif (is_string($haystack)) {
94
            if (!is_string($needle)) {
95
                throw InvalidArgumentHelper::factory(1, 'string');
96
            }
97
98
            $constraint = new StringContains($needle, $ignoreCase);
99
        } else {
100
            throw InvalidArgumentHelper::factory(2, 'array, traversable or string');
101
        }
102
103
        Assert::assertThat($haystack, $constraint, $message);
104
    }
105
106
    /**
107
     * @param mixed  $needle
108
     * @param mixed  $haystack
109
     * @param string $message
110
     * @param bool   $ignoreCase
111
     * @param bool   $checkForObjectIdentity
112
     * @param bool   $checkForNonObjectIdentity
113
     */
114 View Code Duplication
    public static function assertNotContains(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
115
        $needle,
116
        $haystack,
117
        string $message = '',
118
        bool $ignoreCase = false,
119
        bool $checkForObjectIdentity = true,
120
        bool $checkForNonObjectIdentity = false
121
    ): void {
122
        if (is_array($haystack) || is_object($haystack) && $haystack instanceof \Traversable) {
123
            $constraint = new LogicalNot(
124
                self::contains($needle, $checkForObjectIdentity, $checkForNonObjectIdentity)
125
            );
126
        } elseif (is_string($haystack)) {
127
            if (!is_string($needle)) {
128
                throw InvalidArgumentHelper::factory(1, 'string');
129
            }
130
131
            $constraint = new LogicalNot(
132
                new StringContains($needle, $ignoreCase)
133
            );
134
        } else {
135
            throw InvalidArgumentHelper::factory(2, 'array, traversable or string');
136
        }
137
138
        Assert::assertThat($haystack, $constraint, $message);
139
    }
140
141
    /**
142
     * @param mixed $value
143
     * @param float $delta
144
     * @param int   $maxDepth
145
     * @param bool  $canonicalize
146
     * @param bool  $ignoreCase
147
     *
148
     * @return PHPUnitIsEqual
149
     */
150
    public static function equalTo(
151
        $value,
152
        float $delta = 0.0,
153
        int $maxDepth = 10,
154
        bool $canonicalize = false,
155
        bool $ignoreCase = false
156
    ): PHPUnitIsEqual {
157
        return new IsEqual(
158
            $value,
159
            $delta,
160
            $maxDepth,
161
            $canonicalize,
162
            $ignoreCase
163
        );
164
    }
165
166
    /**
167
     * @param string $attributeName
168
     * @param mixed  $value
169
     * @param float  $delta
170
     * @param int    $maxDepth
171
     * @param bool   $canonicalize
172
     * @param bool   $ignoreCase
173
     *
174
     * @return Attribute
175
     */
176
    public static function attributeEqualTo(
177
        string $attributeName,
178
        $value,
179
        float $delta = 0.0,
180
        int $maxDepth = 10,
181
        bool $canonicalize = false,
182
        bool $ignoreCase = false
183
    ): Attribute {
184
        return Assert::attribute(
185
            self::equalTo($value, $delta, $maxDepth, $canonicalize, $ignoreCase),
186
            $attributeName
187
        );
188
    }
189
190
    /**
191
     * @param mixed $value
192
     * @param bool  $checkForObjectIdentity
193
     * @param bool  $checkForNonObjectIdentity
194
     *
195
     * @return PHPUnitTraversableContains
196
     */
197
    public static function contains(
198
        $value,
199
        bool $checkForObjectIdentity = true,
200
        bool $checkForNonObjectIdentity = false
201
    ): PHPUnitTraversableContains {
202
        return new EquatableCollectionContains($value, $checkForObjectIdentity, $checkForNonObjectIdentity);
203
    }
204
}
205