Passed
Push — master ( 5153a0...c7b3db )
by Josh
03:56
created

ArrayHasInstanceOf::matches()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 10
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