GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#100)
by joseph
18:26
created

injectValidatorIfNotNull()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A AbstractEntityRepository::findBy() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Repositories;
4
5
use Doctrine\Common\Collections\Criteria;
6
use Doctrine\ORM\EntityManagerInterface;
7
use Doctrine\ORM\EntityRepository;
8
use Doctrine\ORM\LazyCriteriaCollection;
9
use Doctrine\ORM\Mapping\ClassMetadata;
10
use Doctrine\ORM\NativeQuery;
11
use Doctrine\ORM\Query;
12
use Doctrine\ORM\QueryBuilder;
13
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper;
14
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
15
16
/**
17
 * Class AbstractEntityRepository
18
 *
19
 * This provides a base class that handles instantiating the correctly configured EntityRepository and provides an
20
 * extensible baseline for further customisation
21
 *
22
 * We have extracted an interface from the standard Doctrine EntityRepository and implemented that
23
 * However, so we can add type safety, we can't "actually" implement it
24
 *
25
 * We have also deliberately left out the magic calls. Please make real methods in your concrete repository class
26
 *
27
 * Note, there are quite a few PHPMD warnings, however it needs to respect the legacy interface so they are being
28
 * suppressed
29
 *
30
 * @package EdmondsCommerce\DoctrineStaticMeta\Entity\Repositories
31
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
32
 * @SuppressWarnings(PHPMD.ExcessivePublicCount)
33
 * @SuppressWarnings(PHPMD.NumberOfChildren)
34
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
35
 */
36
abstract class AbstractEntityRepository implements EntityRepositoryInterface
37
{
38
    /**
39
     * @var EntityManagerInterface
40
     */
41
    protected $entityManager;
42
    /**
43
     * @var EntityRepository
44
     */
45
    protected $entityRepository;
46
    /**
47
     * @var string
48
     */
49
    protected $repositoryFactoryFqn;
50
    /**
51
     * @var ClassMetadata|null
52
     */
53
    protected $metaData;
54
    /**
55
     * @var NamespaceHelper
56
     */
57
    protected $namespaceHelper;
58
59
    /**
60
     * AbstractEntityRepositoryFactory constructor.
61
     *
62
     * @param EntityManagerInterface $entityManager
63
     * @param ClassMetadata|null     $metaData
64
     * @param NamespaceHelper|null   $namespaceHelper
65
     */
66 43
    public function __construct(
67
        EntityManagerInterface $entityManager,
68
        ?ClassMetadata $metaData = null,
69
        ?NamespaceHelper $namespaceHelper = null
70
    ) {
71 43
        $this->entityManager   = $entityManager;
72 43
        $this->metaData        = $metaData;
73 43
        $this->namespaceHelper = ($namespaceHelper ?? new NamespaceHelper());
74 43
        $this->initRepository();
75 43
    }
76
77 43
    protected function initRepository(): void
78
    {
79 43
        if (null === $this->metaData) {
80 1
            $entityFqn      = $this->getEntityFqn();
81 1
            $this->metaData = $this->entityManager->getClassMetadata($entityFqn);
82
        }
83
84 43
        $this->entityRepository = new EntityRepository($this->entityManager, $this->metaData);
85 43
    }
86
87 1
    protected function getEntityFqn(): string
88
    {
89 1
        return '\\' . \str_replace(
90
            [
91 1
                    'Entity\\Repositories',
92
                ],
93
            [
94 1
                    'Entities',
95
                ],
96 1
            $this->namespaceHelper->cropSuffix(static::class, 'Repository')
97
        );
98
    }
99
100 1
    public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?EntityInterface
101
    {
102 1
        $entity = $this->entityRepository->find($id, $lockMode, $lockVersion);
103 1
        if (null === $entity || $entity instanceof EntityInterface) {
104 1
            return $entity;
105
        }
106
        throw new \TypeError('Returned result is neither null nor an instance of EntityInterface');
107
    }
108
109
    /**
110
     * @return array|EntityInterface[]
111
     */
112 32
    public function findAll(): array
113
    {
114 32
        return $this->entityRepository->findAll();
115
    }
116
117
    /**
118
     * @return array|EntityInterface[]
119
     */
120 1
    public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
121
    {
122 1
        return $this->entityRepository->findBy($criteria, $orderBy, $limit, $offset);
123
    }
124
125 1
    public function findOneBy(array $criteria, ?array $orderBy = null): ?EntityInterface
126
    {
127 1
        $entity = $this->entityRepository->findOneBy($criteria, $orderBy);
128 1
        if (null === $entity || $entity instanceof EntityInterface) {
129 1
            return $entity;
130
        }
131
        throw new \TypeError('Returned result is neither null nor an instance of EntityInterface');
132
    }
133
134 2
    public function getClassName(): string
135
    {
136 2
        return $this->entityRepository->getClassName();
137
    }
138
139 1
    public function matching(Criteria $criteria): LazyCriteriaCollection
140
    {
141 1
        $collection = $this->entityRepository->matching($criteria);
142 1
        if ($collection instanceof LazyCriteriaCollection) {
0 ignored issues
show
introduced by
$collection is always a sub-type of Doctrine\ORM\LazyCriteriaCollection.
Loading history...
143 1
            return $collection;
144
        }
145
        throw new \TypeError('Returned result is not an instance of LazyCriteriaCollection');
146
    }
147
148 1
    public function createQueryBuilder(string $alias, string $indexBy = null): QueryBuilder
149
    {
150 1
        return $this->entityRepository->createQueryBuilder($alias, $indexBy);
151
    }
152
153 1
    public function createResultSetMappingBuilder(string $alias): Query\ResultSetMappingBuilder
154
    {
155 1
        return $this->entityRepository->createResultSetMappingBuilder($alias);
156
    }
157
158
    public function createNamedQuery(string $queryName): Query
159
    {
160
        return $this->entityRepository->createNamedQuery($queryName);
161
    }
162
163
    public function createNativeNamedQuery(string $queryName): NativeQuery
164
    {
165
        return $this->entityRepository->createNativeNamedQuery($queryName);
166
    }
167
168 1
    public function clear(): void
169
    {
170 1
        $this->entityRepository->clear();
171 1
    }
172
173 1
    public function count(array $criteria): int
174
    {
175 1
        return $this->entityRepository->count($criteria);
176
    }
177
}
178