1 | <?php |
||
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) |
||
56 | |||
57 | /** |
||
58 | * |
||
59 | * |
||
60 | */ |
||
61 | public function executeFixtureAction() |
||
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); |
||
97 | |||
98 | $executor = $this->getFixtureExecutorManager()->get($executorName); |
||
99 | |||
100 | switch ($method) { |
||
101 | case 'import': { |
||
102 | $executor->import(); |
||
103 | break; |
||
104 | } |
||
105 | case 'purge': { |
||
106 | $executor->purge(); |
||
107 | break; |
||
108 | } |
||
109 | } |
||
110 | } |
||
160 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.