Completed
Push — dev ( 14e4a6...854686 )
by Андрей
02:59
created

ExecutorController::getFixtureExecutorManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
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-fixture-module
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\DoctrineFixtureModule\Controller;
7
8
use Nnx\DoctrineFixtureModule\Executor\FixtureExecutorManagerInterface;
9
use Nnx\DoctrineFixtureModule\Utils\ManagerRegistryProviderInterface;
10
use Zend\Mvc\Controller\AbstractConsoleController;
11
use Zend\Console\Request as ConsoleRequest;
12
13
/**
14
 * Class ExecutorController
15
 *
16
 * @package Nnx\DoctrineFixtureModule\Entity
17
 *
18
 */
19
class ExecutorController extends AbstractConsoleController
20
{
21
    /**
22
     * Провайдер для получения ManagerRegistry
23
     *
24
     * @var ManagerRegistryProviderInterface
25
     */
26
    protected $managerRegistryProvider;
27
28
    /**
29
     * Менеджер для получения Executor'ов
30
     *
31
     * @var FixtureExecutorManagerInterface
32
     */
33
    protected $fixtureExecutorManager;
34
35
    /**
36
     * Разрешенные методы
37
     *
38
     * @var array
39
     */
40
    protected $allowedMethod = [
41
        'import',
42
        'purge'
43
    ];
44
45
    /**
46
     * ExecutorController constructor.
47
     *
48
     * @param ManagerRegistryProviderInterface $managerRegistryProvider
49
     * @param FixtureExecutorManagerInterface  $fixtureExecutorManager
50
     */
51
    public function __construct(ManagerRegistryProviderInterface $managerRegistryProvider, FixtureExecutorManagerInterface $fixtureExecutorManager)
52
    {
53
        $this->setManagerRegistryProvider($managerRegistryProvider);
54
        $this->setFixtureExecutorManager($fixtureExecutorManager);
55
    }
56
57
    /**
58
     *
59
     *
60
     */
61
    public function executeFixtureAction()
62
    {
63
        $request = $this->getRequest();
0 ignored issues
show
Unused Code introduced by
$request 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...
64
    }
65
66
67
    /**
68
     *
69
     *
70
     * @throws \Nnx\DoctrineFixtureModule\Controller\Exception\RuntimeException
71
     */
72
    public function runExecutorAction()
73
    {
74
        $request = $this->getRequest();
75
        if (!$request instanceof ConsoleRequest) {
76
            $errMsg = 'Request is not console';
77
            throw new Exception\RuntimeException($errMsg);
78
        }
79
80
        $executorName = $request->getParam('executorName', null);
81
        if (null === $executorName) {
82
            $errMsg = 'Executor name is not defined';
83
            throw new Exception\RuntimeException($errMsg);
84
        }
85
        $method       = $request->getParam('method', null);
86
        if (null === $method) {
87
            $errMsg = 'Executor method not defined';
88
            throw new Exception\RuntimeException($errMsg);
89
        }
90
        $normalizeMethod = strtolower($method);
91
        if (!in_array($normalizeMethod, $this->allowedMethod, true)) {
92
            $errMsg = sprintf('Invalid executor method %s', $method);
93
            throw new Exception\RuntimeException($errMsg);
94
        }
95
96
        $objectManager = $request->getParam('object-manager', null);
0 ignored issues
show
Unused Code introduced by
$objectManager 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...
97
98
        $executor = $this->getFixtureExecutorManager()->get($executorName);
99
100
        switch ($method) {
101
            case 'import': {
0 ignored issues
show
Coding Style introduced by
CASE statements must be defined using a colon

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
102
                $executor->import();
103
                break;
104
            }
105
            case 'purge': {
0 ignored issues
show
Coding Style introduced by
CASE statements must be defined using a colon

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
106
                $executor->purge();
107
                break;
108
            }
109
        }
110
    }
111
112
    /**
113
     * Возвращает провайдер для получения ManagerRegistry
114
     *
115
     * @return ManagerRegistryProviderInterface
116
     */
117
    public function getManagerRegistryProvider()
118
    {
119
        return $this->managerRegistryProvider;
120
    }
121
122
    /**
123
     * Устанавливает провайдер для получения ManagerRegistry
124
     *
125
     * @param ManagerRegistryProviderInterface $managerRegistryProvider
126
     *
127
     * @return $this
128
     */
129
    public function setManagerRegistryProvider(ManagerRegistryProviderInterface $managerRegistryProvider)
130
    {
131
        $this->managerRegistryProvider = $managerRegistryProvider;
132
133
        return $this;
134
    }
135
136
    /**
137
     * Возвращает менеджер для получения Executor'ов
138
     *
139
     * @return FixtureExecutorManagerInterface
140
     */
141
    public function getFixtureExecutorManager()
142
    {
143
        return $this->fixtureExecutorManager;
144
    }
145
146
    /**
147
     * Устанавливает менеджер для получения Executor'ов
148
     *
149
     * @param FixtureExecutorManagerInterface $fixtureExecutorManager
150
     *
151
     * @return $this
152
     */
153
    public function setFixtureExecutorManager($fixtureExecutorManager)
154
    {
155
        $this->fixtureExecutorManager = $fixtureExecutorManager;
156
157
        return $this;
158
    }
159
}
160