| Conditions | 4 |
| Paths | 4 |
| Total Lines | 20 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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); |
||
|
|
|||
| 31 | } |
||
| 33 |