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

EloquentCollectionContains   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toString() 0 3 1
A __construct() 0 3 1
A matches() 0 3 1
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