EntityManager::getSupport()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.2
cc 4
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace Starkerxp\StructureBundle\Manager;
4
5
use Doctrine\ORM\EntityRepository;
6
use Starkerxp\StructureBundle\Entity\AbstractEntity;
7
8
class EntityManager implements ManagerInterface
9
{
10
    /**
11
     * @var array
12
     */
13
    private $arrayService = [];
14
15
    /**
16
     * @return mixed
17
     */
18
    public function insert(AbstractEntity $object)
19
    {
20
        if ($managerService = $this->getSupport($object)) {
21
            $managerService->insert($object);
22
23
            return $object;
24
        }
25
26
        return false;
27
    }
28
29
    /**
30
     * @param AbstractEntity $object
31
     *
32
     * @return bool|ManagerInterface
33
     */
34
    public function getSupport(AbstractEntity $object)
35
    {
36
        foreach ($this->arrayService as $service) {
37
            if ($service instanceof ManagerInterface && $service->getSupport($object)) {
38
                return $service;
39
            }
40
        }
41
42
        return false;
43
    }
44
45
    public function update(AbstractEntity $object)
46
    {
47
        if ($managerService = $this->getSupport($object)) {
48
            $managerService->update($object);
49
50
            return $object;
51
        }
52
53
        return false;
54
    }
55
56
    public function delete(AbstractEntity $object)
57
    {
58
        if ($managerService = $this->getSupport($object)) {
59
            $managerService->delete($object);
60
61
            return $object;
62
        }
63
64
        return false;
65
    }
66
67
    /**
68
     * @param ManagerInterface $service
69
     *
70
     * @return $this
71
     */
72
    public function addService(ManagerInterface $service)
73
    {
74
        $this->arrayService[] = $service;
75
76
        return $this;
77
    }
78
79
    /**
80
     * @return array
81
     */
82
    public function getServices()
83
    {
84
        return $this->arrayService;
85
    }
86
87
    /**
88
     * @param AbstractEntity $object
89
     *
90
     * @return bool|EntityRepository
91
     */
92
    public function getRepository(AbstractEntity $object)
93
    {
94
        if (!$manager = $this->getManager($object)) {
95
            return false;
96
        }
97
98
        return $manager->getRepository();
99
    }
100
101
    /**
102
     * @param AbstractEntity $object
103
     *
104
     * @return bool|AbstractManager
0 ignored issues
show
Documentation introduced by
Should the return type not be ManagerInterface|false?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
105
     */
106
    public function getManager(AbstractEntity $object)
107
    {
108
        $managerService = $this->getSupport($object);
109
110
        return $managerService;
111
    }
112
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
113