Completed
Pull Request — master (#777)
by
unknown
02:27
created

ServiceEntityRepository::setEntityManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Doctrine\Bundle\DoctrineBundle\Repository;
4
5
use Doctrine\Common\Persistence\ManagerRegistry;
6
use Doctrine\ORM\EntityManagerInterface;
7
use Doctrine\ORM\EntityRepository;
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(RegistryInterface $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
        parent::__construct($manager, $manager->getClassMetadata($entityClass));
0 ignored issues
show
Documentation introduced by
$manager is of type object<Doctrine\Common\P...nce\ObjectManager>|null, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
33
    }
34
35
    /**
36
     * @param EntityManagerInterface $em
37
     *
38
     * @return ServiceEntityRepository
39
     */
40
    public function setEntityManager(EntityManagerInterface $em)
41
    {
42
        $this->_em = $em;
0 ignored issues
show
Documentation Bug introduced by
$em is of type object<Doctrine\ORM\EntityManagerInterface>, but the property $_em was declared to be of type object<Doctrine\ORM\EntityManager>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

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.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
43
44
        return $this;
45
    }
46
}
47