1 | <?php |
||
26 | trait RepositoryTrait |
||
27 | { |
||
28 | protected static $supportedMethods = ['findBy', 'findOneBy', 'findPaginatedBy', 'removeBy', 'removeOneBy']; |
||
29 | |||
30 | /** |
||
31 | * Auto flush changes. |
||
32 | * |
||
33 | * @var bool |
||
34 | */ |
||
35 | protected $autoFlush = false; |
||
36 | |||
37 | /** |
||
38 | * New object factory. |
||
39 | * |
||
40 | * @var callable |
||
41 | */ |
||
42 | protected $objectFactory; |
||
43 | |||
44 | /** |
||
45 | * Get automatic manager flushing. |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | public function isAutoFlush(): bool |
||
53 | |||
54 | /** |
||
55 | * Set automatic manager flushing. |
||
56 | * |
||
57 | * @param bool $autoFlush |
||
58 | */ |
||
59 | public function setAutoFlush(bool $autoFlush = true) |
||
63 | |||
64 | /** |
||
65 | * Manager flush. |
||
66 | */ |
||
67 | public function flush() |
||
71 | |||
72 | /** |
||
73 | * Set object factory. |
||
74 | * |
||
75 | * @param callable $objectFactory |
||
76 | */ |
||
77 | public function setObjectFactory(callable $objectFactory) |
||
81 | |||
82 | /** |
||
83 | * Find one object by a set of criteria or create a new one. |
||
84 | * |
||
85 | * @param array $criteria |
||
86 | * |
||
87 | * @throws \RuntimeException |
||
88 | * |
||
89 | * @return object |
||
90 | */ |
||
91 | public function findOneByOrGetNew(array $criteria) |
||
101 | |||
102 | /** |
||
103 | * Get a new managed object instance. |
||
104 | * |
||
105 | * @throws \RuntimeException |
||
106 | * |
||
107 | * @return object |
||
108 | */ |
||
109 | public function getNew() |
||
131 | |||
132 | /** |
||
133 | * Add objects. |
||
134 | * |
||
135 | * @param object|object[]|\Traversable $objects |
||
136 | * @param bool $flush |
||
137 | * |
||
138 | * @throws \InvalidArgumentException |
||
139 | */ |
||
140 | public function add($objects, bool $flush = false) |
||
144 | |||
145 | /** |
||
146 | * Remove all objects. |
||
147 | * |
||
148 | * @param bool $flush |
||
149 | */ |
||
150 | public function removeAll(bool $flush = false) |
||
154 | |||
155 | /** |
||
156 | * Remove object filtered by a set of criteria. |
||
157 | * |
||
158 | * @param array $criteria |
||
159 | * @param bool $flush |
||
160 | */ |
||
161 | public function removeBy(array $criteria, bool $flush = false) |
||
165 | |||
166 | /** |
||
167 | * Remove first object filtered by a set of criteria. |
||
168 | * |
||
169 | * @param array $criteria |
||
170 | * @param bool $flush |
||
171 | */ |
||
172 | public function removeOneBy(array $criteria, bool $flush = false) |
||
176 | |||
177 | /** |
||
178 | * Remove objects. |
||
179 | * |
||
180 | * @param object|object[]|\Traversable|string|int $objects |
||
181 | * @param bool $flush |
||
182 | * |
||
183 | * @throws \InvalidArgumentException |
||
184 | */ |
||
185 | public function remove($objects, bool $flush = false) |
||
193 | |||
194 | /** |
||
195 | * Refresh objects. |
||
196 | * |
||
197 | * @param object|object[]|\Traversable $objects |
||
198 | * |
||
199 | * @throws \InvalidArgumentException |
||
200 | */ |
||
201 | public function refresh($objects) |
||
210 | |||
211 | /** |
||
212 | * Detach objects. |
||
213 | * |
||
214 | * @param object|object[]|\Traversable $objects |
||
215 | * |
||
216 | * @throws \InvalidArgumentException |
||
217 | */ |
||
218 | public function detach($objects) |
||
227 | |||
228 | /** |
||
229 | * Get all objects count. |
||
230 | * |
||
231 | * @return int |
||
232 | */ |
||
233 | public function countAll(): int |
||
237 | |||
238 | /** |
||
239 | * Get object count filtered by a set of criteria. |
||
240 | * |
||
241 | * @param mixed $criteria |
||
242 | * |
||
243 | * @return int |
||
244 | */ |
||
245 | abstract public function countBy($criteria): int; |
||
246 | |||
247 | /** |
||
248 | * Adds support for magic methods. |
||
249 | * |
||
250 | * @param string $method |
||
251 | * @param array $arguments |
||
252 | * |
||
253 | * @throws \BadMethodCallException |
||
254 | * |
||
255 | * @return mixed |
||
256 | */ |
||
257 | public function __call($method, $arguments) |
||
282 | |||
283 | /** |
||
284 | * Internal method call. |
||
285 | * |
||
286 | * @param string $method |
||
287 | * @param string $fieldName |
||
288 | * @param array $arguments |
||
289 | * |
||
290 | * @throws \BadMethodCallException |
||
291 | * |
||
292 | * @return mixed |
||
293 | */ |
||
294 | protected function callSupportedMethod(string $method, string $fieldName, array $arguments) |
||
316 | |||
317 | /** |
||
318 | * Run manager action. |
||
319 | * |
||
320 | * @param object|object[]|\Traversable $objects |
||
321 | * @param string $action |
||
322 | * @param bool $flush |
||
323 | * |
||
324 | * @throws \InvalidArgumentException |
||
325 | */ |
||
326 | protected function runManagerAction($objects, string $action, bool $flush) |
||
350 | |||
351 | /** |
||
352 | * Flush managed objects. |
||
353 | * |
||
354 | * @param object[] $objects |
||
355 | * @param bool $flush |
||
356 | */ |
||
357 | protected function doFlush(array $objects, bool $flush) |
||
363 | |||
364 | /** |
||
365 | * Check if the object is of the proper type. |
||
366 | * |
||
367 | * @param object $object |
||
368 | * |
||
369 | * @return bool |
||
370 | */ |
||
371 | protected function canBeManaged($object): bool |
||
377 | |||
378 | /** |
||
379 | * Returns the fully qualified class name of the objects managed by the repository. |
||
380 | * |
||
381 | * @return string |
||
382 | */ |
||
383 | abstract public function getClassName(): string; |
||
384 | |||
385 | /** |
||
386 | * Get object manager. |
||
387 | * |
||
388 | * @return \Doctrine\Common\Persistence\ObjectManager |
||
389 | */ |
||
390 | abstract protected function getManager(); |
||
391 | |||
392 | /** |
||
393 | * Get class metadata. |
||
394 | * |
||
395 | * @return \Doctrine\Common\Persistence\Mapping\ClassMetadata |
||
396 | */ |
||
397 | abstract protected function getClassMetadata(); |
||
398 | } |
||
399 |
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.