Completed
Push — 2.0 ( 5877a9...9fa07d )
by Peter
07:07 queued 10s
created

RepositoryFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRepository() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of the Happyr Doctrine Specification package.
6
 *
7
 * (c) Tobias Nyholm <[email protected]>
8
 *     Kacper Gunia <[email protected]>
9
 *     Peter Gribanov <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Happyr\DoctrineSpecification\Repository;
16
17
use Doctrine\ORM\EntityManagerInterface;
18
use Doctrine\ORM\EntityRepository;
19
use Doctrine\ORM\Repository\RepositoryFactory as RepositoryFactoryInterface;
20
21
/**
22
 * Factory class for creating EntitySpecificationRepository instances.
23
 *
24
 * Provides an implementation of RepositoryFactory so that the
25
 * default repository type in Doctrine can easily be replaced.
26
 */
27
class RepositoryFactory implements RepositoryFactoryInterface
28
{
29
    /**
30
     * Gets the repository for an entity class.
31
     *
32
     * @param EntityManagerInterface $entityManager the EntityManager instance
33
     * @param string                 $entityName    the name of the entity
34
     *
35
     * @return EntityRepository
36
     *
37
     * @phpstan-template T
38
     * @phpstan-param class-string<T> $entityName
39
     * @phpstan-return EntityRepository<T>
40
     */
41
    public function getRepository(EntityManagerInterface $entityManager, $entityName): EntityRepository
42
    {
43
        return new EntitySpecificationRepository($entityManager, $entityManager->getClassMetadata($entityName));
0 ignored issues
show
Compatibility introduced by
$entityManager->getClassMetadata($entityName) 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...
44
    }
45
}
46