GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ClassMetadataFactoryWithEntityFactories   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
eloc 16
dl 0
loc 49
rs 10
c 0
b 0
f 0
ccs 0
cts 31
cp 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntityFactories() 0 3 1
A wakeupReflection() 0 5 2
A addEntityFactory() 0 3 1
A newClassMetadataInstance() 0 6 1
A setEntityManager() 0 4 1
A addGenericFactory() 0 3 1
1
<?php
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\EntityManager\Mapping;
4
5
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
6
use Doctrine\Common\Persistence\Mapping\ReflectionService;
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\ORM\Mapping\ClassMetadataFactory;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Factory\EntityFactoryInterface as GenericEntityFactoryInterface;
10
11
class ClassMetadataFactoryWithEntityFactories extends ClassMetadataFactory implements EntityFactoryAware
12
{
13
    /** @var EntityFactoryInterface[] */
14
    public static $entityFactories = [];
15
    /** @var GenericEntityFactoryInterface|null */
16
    public static $genericFactory;
17
18
    /** @var EntityManagerInterface */
19
    private $entityManager;
20
21
    public function setEntityManager(EntityManagerInterface $entityManager)
22
    {
23
        parent::setEntityManager($entityManager);
24
        $this->entityManager = $entityManager;
25
    }
26
27
    public function addEntityFactory(string $name, EntityFactoryInterface $entityFactory): void
28
    {
29
        self::$entityFactories[$name] = $entityFactory;
30
    }
31
32
    public function addGenericFactory(GenericEntityFactoryInterface $genericFactory): void
33
    {
34
        self::$genericFactory = $genericFactory;
35
    }
36
37
    public function wakeupReflection(ClassMetadata $class, ReflectionService $reflectionService): void
38
    {
39
        parent::wakeupReflection($class, $reflectionService);
40
        if ($class instanceof ClassMetadataWithEntityFactories) {
41
            $class->setFactories(self::$entityFactories, self::$genericFactory);
42
        }
43
    }
44
45
    protected function newClassMetadataInstance($className): ClassMetadata
46
    {
47
        return new ClassMetadataWithEntityFactories(
48
            $className,
49
            $this->entityManager->getConfiguration()->getNamingStrategy(),
50
            $this->getEntityFactories()
51
        );
52
    }
53
54
    /**
55
     * @return EntityFactoryInterface[]
56
     */
57
    public function getEntityFactories(): array
58
    {
59
        return self::$entityFactories;
60
    }
61
}
62