Completed
Pull Request — develop (#8)
by Josh
09:39
created

ArrayHasInstanceOf   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 26
ccs 10
cts 10
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A matches() 0 9 3
A __construct() 0 3 1
A toString() 0 3 1
1
<?php
2
3
namespace JoshGaber\NovaUnit\Constraints;
4
5
use PHPUnit\Framework\Constraint\Constraint;
6
7
class ArrayHasInstanceOf extends Constraint
8
{
9
    private $class;
10
11 4
    public function __construct(string $class)
12
    {
13 4
        $this->class = $class;
14 4
    }
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 2
    public function toString(): string
20
    {
21 2
        return \sprintf('contains instance of "%s"', $this->class);
22
    }
23
24 4
    public function matches($other): bool
25
    {
26 4
        foreach ($other as $field) {
27 4
            if ($field instanceof $this->class) {
28 4
                return true;
29
            }
30
        }
31
32 2
        return false;
33
    }
34
}
35