Completed
Push — dev ( 867b7a...526cfa )
by Андрей
02:26
created

getDoctrineObjectManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/doctrine
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\Doctrine\Controller;
7
8
use Zend\Mvc\Controller\AbstractConsoleController;
9
use Zend\Console\Request;
10
use Interop\Container\ContainerInterface;
11
use Zend\View\Model\ConsoleModel;
12
use Nnx\Doctrine\Utils\EntityMapBuilderInterface;
13
14
/**
15
 * Class EntityMapBuilderController
16
 *
17
 * @package Nnx\Doctrine\Controller
18
 */
19
class EntityMapBuilderController extends AbstractConsoleController
20
{
21
    /**
22
     * Менеджер для получения ObjectManager Doctrine2
23
     *
24
     * @var ContainerInterface
25
     */
26
    protected $doctrineObjectManager;
27
28
    /**
29
     * Билдер для генерации карты сущностей
30
     *
31
     * @var EntityMapBuilderInterface
32
     */
33
    protected $entityMapBuilder;
34
35
    /**
36
     * EntityMapBuilderController constructor.
37
     *
38
     * @param ContainerInterface        $doctrineObjectManager
39
     * @param EntityMapBuilderInterface $entityMapBuilder
40
     */
41
    public function __construct(ContainerInterface $doctrineObjectManager, EntityMapBuilderInterface $entityMapBuilder)
42
    {
43
        $this->setDoctrineObjectManager($doctrineObjectManager);
44
        $this->setEntityMapBuilder($entityMapBuilder);
45
    }
46
47
48
    /**
49
     * Генерация карты сущностей и сохранение ее в кеше
50
     *
51
     */
52
    public function buildAction()
53
    {
54
        /** @var Request $request */
55
        $request = $this->getRequest();
56
        $managerName = $request->getParam('objectManager');
57
58
        if (!$this->getDoctrineObjectManager()->has($managerName)) {
59
            return [
60
                ConsoleModel::RESULT => sprintf('Doctrine ObjectManager %s not found', $managerName)
61
            ];
62
        }
63
64
        $entityMap = $this->getEntityMapBuilder()->buildEntityMapByObjectManagerName($managerName);
0 ignored issues
show
Unused Code introduced by
$entityMap is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
65
66
        $result = '';
67
68
69
        return [
70
            ConsoleModel::RESULT => $result
71
        ];
72
    }
73
74
    /**
75
     * Возвращает менеджер для получения ObjectManager Doctrine2
76
     *
77
     * @return ContainerInterface
78
     */
79
    public function getDoctrineObjectManager()
80
    {
81
        return $this->doctrineObjectManager;
82
    }
83
84
    /**
85
     * Устанавливает менеджер для получения ObjectManager Doctrine2
86
     *
87
     * @param ContainerInterface $doctrineObjectManager
88
     *
89
     * @return $this
90
     */
91
    public function setDoctrineObjectManager(ContainerInterface $doctrineObjectManager)
92
    {
93
        $this->doctrineObjectManager = $doctrineObjectManager;
94
95
        return $this;
96
    }
97
98
    /**
99
     * Возвращает билдер для генерации карты сущностей
100
     *
101
     * @return EntityMapBuilderInterface
102
     */
103
    public function getEntityMapBuilder()
104
    {
105
        return $this->entityMapBuilder;
106
    }
107
108
    /**
109
     * Устанавливает билдер для генерации карты сущностей
110
     *
111
     * @param EntityMapBuilderInterface $entityMapBuilder
112
     *
113
     * @return $this
114
     */
115
    public function setEntityMapBuilder(EntityMapBuilderInterface $entityMapBuilder)
116
    {
117
        $this->entityMapBuilder = $entityMapBuilder;
118
119
        return $this;
120
    }
121
}
122