1414
1515use Doctrine \Common \Collections \Criteria ;
1616use Doctrine \ORM \EntityManager ;
17+ use Doctrine \ORM \EntityManagerInterface ;
1718use Doctrine \ORM \EntityRepository ;
1819use Doctrine \ORM \LazyCriteriaCollection ;
1920use Doctrine \ORM \NativeQuery ;
2021use Doctrine \ORM \Query ;
2122use Doctrine \ORM \Query \ResultSetMappingBuilder ;
2223use Doctrine \ORM \QueryBuilder ;
2324use Doctrine \ORM \Tools \Pagination \Paginator ;
25+ use Doctrine \Common \Collections \AbstractLazyCollection ;
26+ use Doctrine \Common \Collections \Selectable ;
2427use Illuminate \Support \Facades \Log ;
2528use LaravelDoctrine \ORM \Facades \Registry ;
2629use models \utils \IBaseRepository ;
@@ -45,7 +48,7 @@ abstract class DoctrineRepository extends EntityRepository implements IBaseRepos
4548 /**
4649 * @return EntityManager
4750 */
48- protected function getEntityManager ()
51+ protected function getEntityManager (): EntityManagerInterface
4952 {
5053 return Registry::getManager ($ this ->manager_name );
5154 }
@@ -341,11 +344,11 @@ public function getAllIdsByPage(PagingInfo $paging_info, Filter $filter = null,
341344 *
342345 * @return QueryBuilder
343346 */
344- public function createQueryBuilder ($ alias , $ indexBy = null )
347+ public function createQueryBuilder ($ alias , $ indexBy = null ): QueryBuilder
345348 {
346349 return $ this ->getEntityManager ()->createQueryBuilder ()
347350 ->select ($ alias )
348- ->from ($ this ->_entityName , $ alias , $ indexBy );
351+ ->from ($ this ->getEntityName () , $ alias , $ indexBy );
349352 }
350353
351354 /**
@@ -357,10 +360,10 @@ public function createQueryBuilder($alias, $indexBy = null)
357360 *
358361 * @return ResultSetMappingBuilder
359362 */
360- public function createResultSetMappingBuilder ($ alias )
363+ public function createResultSetMappingBuilder ($ alias ): ResultSetMappingBuilder
361364 {
362365 $ rsm = new ResultSetMappingBuilder ($ this ->getEntityManager (), ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT );
363- $ rsm ->addRootEntityFromClassMetadata ($ this ->_entityName , $ alias );
366+ $ rsm ->addRootEntityFromClassMetadata ($ this ->getEntityName () , $ alias );
364367
365368 return $ rsm ;
366369 }
@@ -414,10 +417,10 @@ public function clear()
414417 *
415418 * @return object|null The entity instance or NULL if the entity can not be found.
416419 */
417- public function find ($ id , $ lockMode = null , $ lockVersion = null , $ refresh = false )
420+ public function find ($ id , $ lockMode = null , $ lockVersion = null , $ refresh = false ): ? object
418421 {
419422 $ em = $ this ->getEntityManager ();
420- $ res = $ em ->find ($ this ->_entityName , $ id , $ lockMode , $ lockVersion );
423+ $ res = $ em ->find ($ this ->getEntityName () , $ id , $ lockMode , $ lockVersion );
421424 if ($ refresh )
422425 $ em ->refresh ($ res );
423426 return $ res ;
@@ -433,9 +436,9 @@ public function find($id, $lockMode = null, $lockVersion = null, $refresh = fals
433436 *
434437 * @return array The objects.
435438 */
436- public function findBy (array $ criteria , array $ orderBy = null , $ limit = null , $ offset = null )
439+ public function findBy (array $ criteria , array $ orderBy = null , $ limit = null , $ offset = null ): array
437440 {
438- $ persister = $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->_entityName );
441+ $ persister = $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->getEntityName () );
439442
440443 return $ persister ->loadAll ($ criteria , $ orderBy , $ limit , $ offset );
441444 }
@@ -448,9 +451,9 @@ public function findBy(array $criteria, array $orderBy = null, $limit = null, $o
448451 *
449452 * @return object|null The entity instance or NULL if the entity can not be found.
450453 */
451- public function findOneBy (array $ criteria , array $ orderBy = null )
454+ public function findOneBy (array $ criteria , array $ orderBy = null ): ? object
452455 {
453- $ persister = $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->_entityName );
456+ $ persister = $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->getEntityName () );
454457
455458 return $ persister ->load ($ criteria , null , null , [], null , 1 , $ orderBy );
456459 }
@@ -464,22 +467,22 @@ public function findOneBy(array $criteria, array $orderBy = null)
464467 *
465468 * @return int The cardinality of the objects that match the given criteria.
466469 */
467- public function count (array $ criteria)
470+ public function count (array $ criteria = []): int
468471 {
469- return $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->_entityName )->count ($ criteria );
472+ return $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->getEntityName () )->count ($ criteria );
470473 }
471474
472475 /**
473476 * Select all elements from a selectable that match the expression and
474477 * return a new collection containing these elements.
475478 *
476- * @param \Doctrine\Common\Collections\ Criteria $criteria
479+ * @param Criteria $criteria
477480 *
478- * @return \Doctrine\Common\Collections\Collection
481+ * @return AbstractLazyCollection&Selectable
479482 */
480- public function matching (Criteria $ criteria )
483+ public function matching (Criteria $ criteria ): AbstractLazyCollection & Selectable
481484 {
482- $ persister = $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->_entityName );
485+ $ persister = $ this ->getEntityManager ()->getUnitOfWork ()->getEntityPersister ($ this ->getEntityName () );
483486
484487 return new LazyCriteriaCollection ($ persister , $ criteria );
485488 }
0 commit comments