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 (#57)
by joseph
16:59
created

AbstractEntityRepository::findAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 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\EntityManager;
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 EntityManager
40
     */
41
    protected $entityManager;
42
43
    /**
44
     * @var EntityRepository
45
     */
46
    protected $entityRepository;
47
48
    /**
49
     * @var string
50
     */
51
    protected $repositoryFactoryFqn;
52
    /**
53
     * @var ClassMetadata|null
54
     */
55
    protected $metaData;
56
    /**
57
     * @var NamespaceHelper
58
     */
59
    protected $namespaceHelper;
60
61
    /**
62
     * AbstractEntityRepositoryFactory constructor.
63
     *
64
     * @param EntityManager        $entityManager
65
     * @param ClassMetadata|null   $metaData
66
     * @param NamespaceHelper|null $namespaceHelper
67
     */
68 30
    public function __construct(
69
        EntityManager $entityManager,
70
        ?ClassMetadata $metaData = null,
71
        ?NamespaceHelper $namespaceHelper = null
72
    ) {
73 30
        $this->entityManager   = $entityManager;
74 30
        $this->metaData        = $metaData;
75 30
        $this->namespaceHelper = ($namespaceHelper ?? new NamespaceHelper());
76 30
        $this->initRepository();
77 30
    }
78
79 30
    protected function initRepository(): void
80
    {
81 30
        if (null === $this->metaData) {
82 1
            $entityFqn      = $this->getEntityFqn();
83 1
            $this->metaData = $this->entityManager->getClassMetadata($entityFqn);
84
        }
85
86 30
        $this->entityRepository = new EntityRepository($this->entityManager, $this->metaData);
87 30
    }
88
89 1
    protected function getEntityFqn(): string
90
    {
91 1
        return '\\'.\str_replace(
92
                [
93 1
                    'Entity\\Repositories',
94
                ],
95
                [
96 1
                    'Entities',
97
                ],
98 1
                $this->namespaceHelper->cropSuffix(static::class, 'Repository')
99
            );
100
    }
101
102 1
    public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?EntityInterface
103
    {
104 1
        $result = $this->entityRepository->find($id, $lockMode, $lockVersion);
105 1
        if (null === $result || $result instanceof EntityInterface) {
106 1
            return $result;
107
        }
108
        throw new \TypeError('Returned result is neither null nor an instance of EntityInterface');
109
    }
110
111 19
    public function findAll(): array
112
    {
113 19
        return $this->entityRepository->findAll();
114
    }
115
116 1
    public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
117
    {
118 1
        return $this->entityRepository->findBy($criteria, $orderBy, $limit, $offset);
119
    }
120
121 1
    public function findOneBy(array $criteria, ?array $orderBy = null): ?EntityInterface
122
    {
123 1
        $result = $this->entityRepository->findOneBy($criteria, $orderBy);
124 1
        if (null === $result || $result instanceof EntityInterface) {
125 1
            return $result;
126
        }
127
        throw new \TypeError('Returned result is neither null nor an instance of EntityInterface');
128
    }
129
130 2
    public function getClassName(): string
131
    {
132 2
        return $this->entityRepository->getClassName();
133
    }
134
135 1
    public function matching(Criteria $criteria): LazyCriteriaCollection
136
    {
137 1
        $result = $this->entityRepository->matching($criteria);
138 1
        if ($result instanceof LazyCriteriaCollection) {
0 ignored issues
show
introduced by
$result is always a sub-type of Doctrine\ORM\LazyCriteriaCollection.
Loading history...
139 1
            return $result;
140
        }
141
        throw new \TypeError('Returned result is not an instance of LazyCriteriaCollection');
142
    }
143
144 1
    public function createQueryBuilder(string $alias, string $indexBy = null): QueryBuilder
145
    {
146 1
        return $this->entityRepository->createQueryBuilder($alias, $indexBy);
147
    }
148
149 1
    public function createResultSetMappingBuilder(string $alias): Query\ResultSetMappingBuilder
150
    {
151 1
        return $this->entityRepository->createResultSetMappingBuilder($alias);
152
    }
153
154
    public function createNamedQuery(string $queryName): Query
155
    {
156
        return $this->entityRepository->createNamedQuery($queryName);
157
    }
158
159
    public function createNativeNamedQuery(string $queryName): NativeQuery
160
    {
161
        return $this->entityRepository->createNativeNamedQuery($queryName);
162
    }
163
164 1
    public function clear()
165
    {
166 1
        $this->entityRepository->clear();
167 1
    }
168
169 1
    public function count(array $criteria)
170
    {
171 1
        return $this->entityRepository->count($criteria);
172
    }
173
}
174