|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace TemplateNamespace\Entity\Repositories; |
|
4
|
|
|
|
|
5
|
|
|
use TemplateNamespace\Entity\Repositories\AbstractEntityRepository; |
|
6
|
|
|
use TemplateNamespace\Entity\Interfaces\TemplateEntityInterface; |
|
7
|
|
|
|
|
8
|
|
|
// phpcs:disable -- line length |
|
9
|
|
|
class TemplateEntityRepository extends AbstractEntityRepository |
|
10
|
|
|
{ |
|
11
|
|
|
// phpcs: enable |
|
12
|
|
|
|
|
13
|
|
|
public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?TemplateEntityInterface |
|
14
|
|
|
{ |
|
15
|
|
|
$result = parent::find($id, $lockMode, $lockVersion); |
|
|
|
|
|
|
16
|
|
|
if ($result === null || $result instanceof TemplateEntityInterface) { |
|
|
|
|
|
|
17
|
|
|
return $result; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
throw new \RuntimeException('Unknown entity type of ' . \get_class($result) . ' returned'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function get($id, ?int $lockMode = null, ?int $lockVersion = null): TemplateEntityInterface |
|
24
|
|
|
{ |
|
25
|
|
|
$result = parent::get($id, $lockMode, $lockVersion); |
|
26
|
|
|
if ($result instanceof TemplateEntityInterface) { |
|
27
|
|
|
return $result; |
|
28
|
|
|
} |
|
29
|
|
|
throw new \RuntimeException('Unknown entity type of ' . \get_class($result) . ' returned'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getOneBy(array $criteria, ?array $orderBy = null): TemplateEntityInterface |
|
33
|
|
|
{ |
|
34
|
|
|
$result = $this->findOneBy($criteria, $orderBy); |
|
|
|
|
|
|
35
|
|
|
if ($result === null) { |
|
|
|
|
|
|
36
|
|
|
throw new \RuntimeException('Could not find the entity'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return $result; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function findOneBy(array $criteria, ?array $orderBy = null): ?TemplateEntityInterface |
|
43
|
|
|
{ |
|
44
|
|
|
$result = parent::findOneBy($criteria, $orderBy); |
|
|
|
|
|
|
45
|
|
|
if ($result === null || $result instanceof TemplateEntityInterface) { |
|
|
|
|
|
|
46
|
|
|
return $result; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
throw new \RuntimeException('Unknown entity type of ' . \get_class($result) . ' returned'); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.