1 | <?php |
||
41 | class EntityRepository implements ObjectRepository, Selectable |
||
42 | { |
||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $_entityName; |
||
47 | |||
48 | /** |
||
49 | * @var EntityManager |
||
50 | */ |
||
51 | protected $_em; |
||
52 | |||
53 | /** |
||
54 | * @var \Doctrine\ORM\Mapping\ClassMetadata |
||
55 | */ |
||
56 | protected $_class; |
||
57 | |||
58 | /** |
||
59 | * Initializes a new <tt>EntityRepository</tt>. |
||
60 | * |
||
61 | * @param EntityManager $em The EntityManager to use. |
||
62 | * @param Mapping\ClassMetadata $class The class descriptor. |
||
63 | */ |
||
64 | 144 | public function __construct(EntityManagerInterface $em, Mapping\ClassMetadata $class) |
|
70 | |||
71 | /** |
||
72 | * Creates a new QueryBuilder instance that is prepopulated for this entity name. |
||
73 | * |
||
74 | * @param string $alias |
||
75 | * @param string $indexBy The index for the from. |
||
76 | * |
||
77 | * @return QueryBuilder |
||
78 | */ |
||
79 | 6 | public function createQueryBuilder($alias, $indexBy = null) |
|
85 | |||
86 | /** |
||
87 | * Creates a new result set mapping builder for this entity. |
||
88 | * |
||
89 | * The column naming strategy is "INCREMENT". |
||
90 | * |
||
91 | * @param string $alias |
||
92 | * |
||
93 | * @return ResultSetMappingBuilder |
||
94 | */ |
||
95 | 1 | public function createResultSetMappingBuilder($alias) |
|
102 | |||
103 | /** |
||
104 | * Creates a new Query instance based on a predefined metadata named query. |
||
105 | * |
||
106 | * @param string $queryName |
||
107 | * |
||
108 | * @return Query |
||
109 | */ |
||
110 | 3 | public function createNamedQuery($queryName) |
|
114 | |||
115 | /** |
||
116 | * Creates a native SQL query. |
||
117 | * |
||
118 | * @param string $queryName |
||
119 | * |
||
120 | * @return NativeQuery |
||
121 | */ |
||
122 | 7 | public function createNativeNamedQuery($queryName) |
|
130 | |||
131 | /** |
||
132 | * Clears the repository, causing all managed entities to become detached. |
||
133 | * |
||
134 | * @return void |
||
135 | */ |
||
136 | public function clear() |
||
140 | |||
141 | /** |
||
142 | * Finds an entity by its primary key / identifier. |
||
143 | * |
||
144 | * @param mixed $id The identifier. |
||
145 | * @param int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants |
||
146 | * or NULL if no specific lock mode should be used |
||
147 | * during the search. |
||
148 | * @param int|null $lockVersion The lock version. |
||
149 | * |
||
150 | * @return object|null The entity instance or NULL if the entity can not be found. |
||
151 | */ |
||
152 | 14 | public function find($id, $lockMode = null, $lockVersion = null) |
|
156 | |||
157 | /** |
||
158 | * Finds all entities in the repository. |
||
159 | * |
||
160 | * @return array The entities. |
||
161 | */ |
||
162 | 30 | public function findAll() |
|
166 | |||
167 | /** |
||
168 | * Finds entities by a set of criteria. |
||
169 | * |
||
170 | * @param array $criteria |
||
171 | * @param array|null $orderBy |
||
172 | * @param int|null $limit |
||
173 | * @param int|null $offset |
||
174 | * |
||
175 | * @return array The objects. |
||
176 | */ |
||
177 | 60 | public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
|
183 | |||
184 | /** |
||
185 | * Finds a single entity by a set of criteria. |
||
186 | * |
||
187 | * @param array $criteria |
||
188 | * @param array|null $orderBy |
||
189 | * |
||
190 | * @return object|null The entity instance or NULL if the entity can not be found. |
||
191 | */ |
||
192 | 21 | public function findOneBy(array $criteria, array $orderBy = null) |
|
198 | |||
199 | /** |
||
200 | * Adds support for magic finders. |
||
201 | * |
||
202 | * @param string $method |
||
203 | * @param array $arguments |
||
204 | * |
||
205 | * @return array|object The found entity/entities. |
||
206 | * |
||
207 | * @throws ORMException |
||
208 | * @throws \BadMethodCallException If the method called is an invalid find* method |
||
209 | * or no find* method at all and therefore an invalid |
||
210 | * method call. |
||
211 | */ |
||
212 | 12 | public function __call($method, $arguments) |
|
213 | { |
||
214 | switch (true) { |
||
215 | 12 | case (0 === strpos($method, 'findBy')): |
|
216 | 8 | $by = substr($method, 6); |
|
217 | 8 | $method = 'findBy'; |
|
218 | 8 | break; |
|
219 | |||
220 | 4 | case (0 === strpos($method, 'findOneBy')): |
|
221 | 3 | $by = substr($method, 9); |
|
222 | 3 | $method = 'findOneBy'; |
|
223 | 3 | break; |
|
224 | |||
225 | default: |
||
226 | 1 | throw new \BadMethodCallException( |
|
227 | 1 | "Undefined method '$method'. The method name must start with ". |
|
228 | 1 | "either findBy or findOneBy!" |
|
229 | ); |
||
230 | } |
||
231 | |||
232 | 11 | if (empty($arguments)) { |
|
233 | 1 | throw ORMException::findByRequiresParameter($method . $by); |
|
234 | } |
||
235 | |||
236 | 10 | $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by)); |
|
237 | |||
238 | 10 | if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) { |
|
239 | 9 | switch (count($arguments)) { |
|
240 | 9 | case 1: |
|
241 | 7 | return $this->$method(array($fieldName => $arguments[0])); |
|
242 | |||
243 | 2 | case 2: |
|
244 | 1 | return $this->$method(array($fieldName => $arguments[0]), $arguments[1]); |
|
245 | |||
246 | 1 | case 3: |
|
247 | return $this->$method(array($fieldName => $arguments[0]), $arguments[1], $arguments[2]); |
||
248 | |||
249 | 1 | case 4: |
|
250 | 1 | return $this->$method(array($fieldName => $arguments[0]), $arguments[1], $arguments[2], $arguments[3]); |
|
251 | |||
252 | default: |
||
253 | // Do nothing |
||
254 | } |
||
255 | } |
||
256 | |||
257 | 1 | throw ORMException::invalidFindByCall($this->_entityName, $fieldName, $method.$by); |
|
258 | } |
||
259 | |||
260 | /** |
||
261 | * @return string |
||
262 | */ |
||
263 | protected function getEntityName() |
||
267 | |||
268 | /** |
||
269 | * @return string |
||
270 | */ |
||
271 | public function getClassName() |
||
275 | |||
276 | /** |
||
277 | * @return EntityManager |
||
278 | */ |
||
279 | protected function getEntityManager() |
||
283 | |||
284 | /** |
||
285 | * @return Mapping\ClassMetadata |
||
286 | */ |
||
287 | protected function getClassMetadata() |
||
291 | |||
292 | /** |
||
293 | * Select all elements from a selectable that match the expression and |
||
294 | * return a new collection containing these elements. |
||
295 | * |
||
296 | * @param \Doctrine\Common\Collections\Criteria $criteria |
||
297 | * |
||
298 | * @return \Doctrine\Common\Collections\Collection |
||
299 | */ |
||
300 | 24 | public function matching(Criteria $criteria) |
|
306 | } |
||
307 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.