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.

EquatableCollectionContains   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 65
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A matches() 0 12 4
A failureDescription() 0 12 3
A collectionContainsAnEqualEquatableObject() 0 10 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 F500\Equatable\Map;
13
use F500\Equatable\Vector;
14
use PHPUnit\Framework\Constraint\TraversableContains;
15
16
/**
17
 * @copyright Copyright (c) 2015 Future500 B.V.
18
 * @author    Jasper N. Brouwer <[email protected]>
19
 */
20
final class EquatableCollectionContains extends TraversableContains
21
{
22
    /**
23
     * @var mixed
24
     */
25 27
    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 27
    /**
28 15
     * @inheritdoc
29
     */
30
    public function __construct($value, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false)
31 12
    {
32 6
        parent::__construct($value, $checkForObjectIdentity, $checkForNonObjectIdentity);
33
34
        $this->value = $value;
35 6
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    protected function matches($other): bool
41 12
    {
42
        if ($other instanceof Map || $other instanceof Vector) {
43 12
            return $other->contains($this->value);
44 3
        }
45
46
        if ($this->value instanceof Equatable) {
47 9
            return $this->collectionContainsAnEqualEquatableObject($other);
48 3
        }
49
50
        return parent::matches($other);
51 6
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56
    protected function failureDescription($other): string
57
    {
58
        if ($other instanceof Map) {
59 6
            return 'an equatable map ' . $this->toString();
60
        }
61 6
62 6
        if ($other instanceof Vector) {
63 6
            return 'an equatable vector ' . $this->toString();
64
        }
65
66
        return parent::failureDescription($other);
67 3
    }
68
69
    /**
70
     * @param \Traversable|array $other
71
     *
72
     * @return bool
73
     */
74
    private function collectionContainsAnEqualEquatableObject($other)
75
    {
76
        foreach ($other as $element) {
77
            if ($this->value->equals($element)) {
78
                return true;
79
            }
80
        }
81
82
        return false;
83
    }
84
}
85