| Conditions | 11 |
| Paths | 7 |
| Total Lines | 53 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 111 | public function install( |
||
| 112 | Request $request, |
||
| 113 | ExtensionEntity $extension, |
||
| 114 | ExtensionHelper $extensionHelper |
||
| 115 | ) { |
||
| 116 | $id = $extension->getId(); |
||
| 117 | |||
| 118 | $unsatisfiedDependencies = $this->dependencyHelper->getUnsatisfiedExtensionDependencies($extension); |
||
| 119 | $form = $this->createForm(ExtensionInstallType::class, [ |
||
| 120 | 'dependencies' => $this->formatDependencyCheckboxArray($unsatisfiedDependencies) |
||
| 121 | ]); |
||
| 122 | |||
| 123 | $form->handleRequest($request); |
||
| 124 | if ($form->isSubmitted() && $form->isValid()) { |
||
| 125 | if ($form->get('install')->isClicked()) { |
||
|
|
|||
| 126 | $extensionsInstalled = []; |
||
| 127 | $data = $form->getData(); |
||
| 128 | |||
| 129 | // Install extension dependencies |
||
| 130 | foreach ($data['dependencies'] as $dependencyId => $installSelected) { |
||
| 131 | if (!$installSelected && MetaData::DEPENDENCY_REQUIRED !== $unsatisfiedDependencies[$dependencyId]->getStatus()) { |
||
| 132 | continue; |
||
| 133 | } |
||
| 134 | $dependencyExtensionEntity = $this->extensionRepository->get($unsatisfiedDependencies[$dependencyId]->getModname()); |
||
| 135 | if (isset($dependencyExtensionEntity)) { |
||
| 136 | if (!$extensionHelper->install($dependencyExtensionEntity)) { |
||
| 137 | $this->addFlash('error', $this->trans('Failed to install dependency "%name%"!', ['%name%' => $dependencyExtensionEntity->getName()])); |
||
| 138 | |||
| 139 | return $this->redirectToRoute('zikulaextensionsmodule_extension_list'); |
||
| 140 | } |
||
| 141 | $extensionsInstalled[] = $dependencyExtensionEntity->getId(); |
||
| 142 | $this->addFlash('status', $this->trans('Installed dependency "%name%".', ['%name%' => $dependencyExtensionEntity->getName()])); |
||
| 143 | } else { |
||
| 144 | $this->addFlash('warning', $this->trans('Warning: could not install selected dependency "%name%".', ['%name%' => $unsatisfiedDependencies[$dependencyId]->getModname()])); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | if ($extensionHelper->install($extension)) { |
||
| 149 | $this->addFlash('status', $this->trans('Done! Installed "%name%".', ['%name%' => $extension->getName()])); |
||
| 150 | $extensionsInstalled[] = $id; |
||
| 151 | |||
| 152 | return $this->redirectToRoute('zikulaextensionsmodule_extensioninstaller_postinstall', ['extensions' => json_encode($extensionsInstalled)]); |
||
| 153 | } |
||
| 154 | $this->extensionStateHelper->updateState($id, Constant::STATE_UNINITIALISED); |
||
| 155 | $this->addFlash('error', $this->trans('Initialization of "%name%" failed!', ['%name%' => $extension->getName()])); |
||
| 156 | } |
||
| 157 | if ($form->get('cancel')->isClicked()) { |
||
| 158 | $this->extensionStateHelper->updateState($id, Constant::STATE_UNINITIALISED); |
||
| 159 | $this->addFlash('status', 'Operation cancelled.'); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | return $this->redirectToRoute('zikulaextensionsmodule_extension_list'); |
||
| 164 | } |
||
| 223 |