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.
Completed
Push — master ( b6d48e...df54b5 )
by Romain
02:16
created

DoctrineObjectManager   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 65
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getIdentifierName() 0 6 1
A getIdentifier() 0 15 4
A getRepository() 0 4 1
A getClassMetadata() 0 4 1
1
<?php
2
3
namespace Halapi\ObjectManager;
4
5
use Doctrine\Common\Persistence\ObjectManager;
6
7
/**
8
 * Interface ObjectManagerInterface
9
 * @author Romain Richard
10
 */
11
class DoctrineObjectManager implements ObjectManagerInterface
12
{
13
    /**
14
     * @var ObjectManager
15
     */
16
    private $objectManager;
17
18
    /**
19
     * DoctrineObjectManager constructor.
20
     * @param ObjectManager $objectManager
21
     */
22
    public function __construct(ObjectManager $objectManager)
23
    {
24
        $this->objectManager = $objectManager;
25
    }
26
27
    /**
28
     * @param object $resource
29
     * @return mixed
30
     */
31
    public function getIdentifierName($resource)
32
    {
33
        $classMetadata = $this->objectManager->getClassMetadata(get_class($resource));
34
35
        return $classMetadata->getIdentifier()[0];
36
    }
37
38
    /**
39
     * @param object $resource
40
     * @return mixed
41
     */
42
    public function getIdentifier($resource)
43
    {
44
        $identifier = new \ReflectionProperty($resource, $this->getIdentifier($resource));
45
        if ($identifier->isPublic()) {
46
            return $identifier;
47
        }
48
49
        $getter = 'get'.ucfirst($identifier);
50
        $getterReflection = new \ReflectionMethod($resource, $getter);
51
        if (method_exists($resource, $getter) && $getterReflection->isPublic()) {
52
            return $resource->$getter();
53
        }
54
55
        return;
56
    }
57
58
    /**
59
     * @param string $className
60
     * @return \Doctrine\Common\Persistence\ObjectRepository
61
     */
62
    public function getRepository($className)
63
    {
64
        return $this->objectManager->getRepository($className);
65
    }
66
67
    /**
68
     * @param string $className
69
     * @return \Doctrine\Common\Persistence\Mapping\ClassMetadata
70
     */
71
    public function getClassMetadata($className)
72
    {
73
        return $this->objectManager->getClassMetadata($className);
74
    }
75
}
76