ServiceEntityRepository::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Doctrine\Bundle\DoctrineBundle\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
use Doctrine\Persistence\ManagerRegistry;
7
use LogicException;
8
9
/**
10
 * Optional EntityRepository base class with a simplified constructor (for autowiring).
11
 *
12
 * To use in your class, inject the "registry" service and call
13
 * the parent constructor. For example:
14
 *
15
 * class YourEntityRepository extends ServiceEntityRepository
16
 * {
17
 *     public function __construct(ManagerRegistry $registry)
18
 *     {
19
 *         parent::__construct($registry, YourEntity::class);
20
 *     }
21
 * }
22
 */
23
class ServiceEntityRepository extends EntityRepository implements ServiceEntityRepositoryInterface
24
{
25
    /**
26
     * @param string $entityClass The class name of the entity this repository manages
27
     */
28
    public function __construct(ManagerRegistry $registry, $entityClass)
29
    {
30
        $manager = $registry->getManagerForClass($entityClass);
31
32
        if ($manager === null) {
33
            throw new LogicException(sprintf(
34
                'Could not find the entity manager for class "%s". Check your Doctrine configuration to make sure it is configured to load this entity’s metadata.',
35
                $entityClass
36
            ));
37
        }
38
39
        parent::__construct($manager, $manager->getClassMetadata($entityClass));
0 ignored issues
show
Compatibility introduced by
$manager of type object<Doctrine\Persistence\ObjectManager> is not a sub-type of object<Doctrine\ORM\EntityManagerInterface>. It seems like you assume a child interface of the interface Doctrine\Persistence\ObjectManager to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Compatibility introduced by
$manager->getClassMetadata($entityClass) of type object<Doctrine\Persiste...\Mapping\ClassMetadata> is not a sub-type of object<Doctrine\ORM\Mapping\ClassMetadata>. It seems like you assume a concrete implementation of the interface Doctrine\Persistence\Mapping\ClassMetadata to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
40
    }
41
}
42