1 | <?php |
||
28 | class ORMRepository implements |
||
29 | EntityRepositoryInterface, |
||
30 | DeletableInterface, |
||
31 | FlushableInterface, |
||
32 | ReadableInterface, |
||
33 | TransactionAwareInterface, |
||
34 | WritableInterface |
||
35 | { |
||
36 | /** |
||
37 | * The Doctrine ORM entity manager that is used to retrieve and store data. |
||
38 | * |
||
39 | * @var EntityManagerInterface |
||
40 | */ |
||
41 | protected $entityManager; |
||
42 | |||
43 | /** |
||
44 | * The FQCN of the entity to work with. |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $entityName; |
||
49 | |||
50 | /** |
||
51 | * The Doctrine ORM repository that is used to retrieve and store data. |
||
52 | * |
||
53 | * @var ObjectRepository |
||
54 | */ |
||
55 | protected $repository; |
||
56 | |||
57 | /** |
||
58 | * Initializes the self::$entityManager and self::$entityName |
||
59 | * |
||
60 | * @param EntityManagerInterface $entityManager The Doctrine ORM entity manager used to retrieve and store data. |
||
61 | * @param string $entityName The FQCN of the entity to work with. |
||
62 | */ |
||
63 | 48 | public function __construct(EntityManagerInterface $entityManager, $entityName) |
|
68 | |||
69 | /** |
||
70 | * Counts entities by a set of criteria. |
||
71 | * |
||
72 | * Optionally sorting and limiting details can be passed. An implementation may throw an UnexpectedValueException |
||
73 | * if certain values of the sorting or limiting details are not supported. |
||
74 | * |
||
75 | * @param array|Criteria $criteria The criteria to find entities by. |
||
76 | * @return int Returns the amount of entities that are found. |
||
77 | * @throws \Doctrine\ORM\Query\QueryException |
||
78 | * @throws \Doctrine\ORM\NoResultException |
||
79 | * @throws \Doctrine\ORM\NonUniqueResultException |
||
80 | * @throws UnexpectedValueException |
||
81 | */ |
||
82 | 6 | public function countBy($criteria) |
|
103 | |||
104 | /** |
||
105 | * Deletes the given object |
||
106 | * |
||
107 | * @param object $entity The entity to delete. |
||
108 | */ |
||
109 | 3 | public function delete($entity) |
|
113 | |||
114 | /** |
||
115 | * Removes objects by a set of criteria. |
||
116 | * |
||
117 | * @param array|Criteria $criteria |
||
118 | * @return void |
||
119 | * @throws \Doctrine\ORM\Query\QueryException |
||
120 | */ |
||
121 | 3 | public function deleteBy($criteria) |
|
129 | |||
130 | /** |
||
131 | * Tries to find an entity in the repository by the given identifier. |
||
132 | * |
||
133 | * @param mixed $id The id of the entity which can be any type of object. |
||
134 | * @return object|null Returns the entity that matches the identifier or null when no instance is found. |
||
135 | */ |
||
136 | 3 | public function find($id) |
|
140 | |||
141 | /** |
||
142 | * Tries to find all entities in the repository. |
||
143 | * |
||
144 | * @return object[] Returns an array with entities that are found. |
||
145 | */ |
||
146 | 3 | public function findAll() |
|
150 | |||
151 | /** |
||
152 | * Tries to find entities by a set of criteria. |
||
153 | * |
||
154 | * Optionally sorting and limiting details can be passed. An implementation may throw an UnexpectedValueException |
||
155 | * if certain values of the sorting or limiting details are not supported. |
||
156 | * |
||
157 | * @param array|Criteria $criteria The criteria to find entities by. |
||
158 | * @return array Returns an array with found entities. Returns an empty array when no entities are found. |
||
159 | * @throws \Doctrine\ORM\Query\QueryException |
||
160 | * @throws UnexpectedValueException Thrown when provided parameters are not supported. |
||
161 | */ |
||
162 | 6 | public function findBy($criteria) |
|
170 | |||
171 | /** |
||
172 | * Tries to find a single entity by a set of criteria. |
||
173 | * |
||
174 | * @param array|Criteria $criteria The criteria. The criteria to find the entity by. |
||
175 | * @return object|null Returns the entity that is found or null when no entity is found. |
||
176 | * @throws \Doctrine\ORM\Query\QueryException |
||
177 | * @throws \Doctrine\ORM\NonUniqueResultException |
||
178 | */ |
||
179 | 6 | public function findOneBy($criteria) |
|
190 | |||
191 | /** |
||
192 | * Creates a new query builder using the $criteria. |
||
193 | * |
||
194 | * @param Criteria $criteria |
||
195 | * @return \Doctrine\ORM\QueryBuilder |
||
196 | * @throws \Doctrine\ORM\Query\QueryException |
||
197 | */ |
||
198 | 15 | protected function getQueryBuilder(Criteria $criteria) |
|
206 | |||
207 | /** |
||
208 | * Gets the Doctrine EntityManager. |
||
209 | * |
||
210 | * @return EntityManagerInterface |
||
211 | */ |
||
212 | 3 | public function getEntityManager() |
|
216 | |||
217 | /** |
||
218 | * Returns the doctrine repository. |
||
219 | * |
||
220 | * @return ObjectRepository |
||
221 | */ |
||
222 | 24 | public function getRepository() |
|
230 | |||
231 | /** |
||
232 | * Will flush the given entity. If non given all queued entities will be flushed. |
||
233 | * |
||
234 | * @param object $entity The entity to flush. |
||
235 | * @return void |
||
236 | */ |
||
237 | 3 | public function flush($entity = null) |
|
241 | |||
242 | /** |
||
243 | * Persist the given entity. |
||
244 | * |
||
245 | * @param object $entity The entity to persist. |
||
246 | */ |
||
247 | 3 | public function persist($entity) |
|
251 | |||
252 | /** |
||
253 | * Starts a new transaction. |
||
254 | * |
||
255 | * @return void |
||
256 | */ |
||
257 | 3 | public function beginTransaction() |
|
261 | |||
262 | /** |
||
263 | * Commits a started transaction. |
||
264 | * |
||
265 | * @return void |
||
266 | */ |
||
267 | 3 | public function commitTransaction() |
|
271 | |||
272 | /** |
||
273 | * Rolls back a started transaction. |
||
274 | * |
||
275 | * @return void |
||
276 | */ |
||
277 | 3 | public function rollbackTransaction() |
|
281 | } |
||
282 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.