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

EloquentCollectionContains::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace JoshGaber\NovaUnit\Constraints;
4
5
use Illuminate\Database\Eloquent\Model;
6
use PHPUnit\Framework\Constraint\Constraint;
7
use ReflectionClass;
8
9
class EloquentCollectionContains extends Constraint
10
{
11
    /**
12
     * @var Model
13
     */
14
    private $object;
15
16 4
    public function __construct($object)
17
    {
18 4
        $this->object = $object;
19 4
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 2
    public function toString(): string
25
    {
26 2
        return \sprintf('contains the given %s', (new ReflectionClass($this->object))->getShortName());
27
    }
28
29 4
    public function matches($collection): bool
30
    {
31 4
        return $collection->find($this->object->getKey()) instanceof Model;
32
    }
33
}
34