Passed
Pull Request — master (#55)
by Thomas
01:32
created

EntityManagerMock   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
c 1
b 0
f 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fetch() 0 20 4
1
<?php
2
3
namespace ORM\Testing;
4
5
use ORM\Entity;
6
use ORM\EntityManager;
7
use ORM\Exception\NoEntity;
8
9
class EntityManagerMock extends EntityManager
10
{
11
    public function fetch($class, $primaryKey = null)
12
    {
13
        $reflection = new \ReflectionClass($class);
14
        if (!$reflection->isSubclassOf(Entity::class)) {
15
            throw new NoEntity($class . ' is not a subclass of Entity');
16
        }
17
        /** @var string|Entity $class */
18
19
        if ($primaryKey === null) {
20
            return new EntityFetcherMock($this, $class);
21
        }
22
23
        $primaryKey = $this->buildPrimaryKey($class, (array)$primaryKey);
24
        $checksum = $this->buildChecksum($primaryKey);
25
26
        if (isset($this->map[$class][$checksum])) {
27
            return $this->map[$class][$checksum];
28
        }
29
30
        return EntityFetcherMock::retrieve($class, $primaryKey);
0 ignored issues
show
Bug introduced by
It seems like $class can also be of type ORM\Entity; however, parameter $class of ORM\Testing\EntityFetcherMock::retrieve() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        return EntityFetcherMock::retrieve(/** @scrutinizer ignore-type */ $class, $primaryKey);
Loading history...
31
    }
32
}
33