| Conditions | 10 |
| Paths | 13 |
| Total Lines | 71 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 173 | public function deleteAction(Request $request, $themeName) |
||
| 174 | { |
||
| 175 | if (!$this->hasPermission('ZikulaThemeModule::', "$themeName::", ACCESS_DELETE)) { |
||
| 176 | throw new AccessDeniedException(); |
||
| 177 | } |
||
| 178 | |||
| 179 | $form = $this->createFormBuilder(['themeName' => $themeName, 'deletefiles' => false]) |
||
| 180 | ->add('themeName', HiddenType::class) |
||
| 181 | ->add('deletefiles', CheckboxType::class, [ |
||
| 182 | 'label' => $this->__('Also delete theme files, if possible'), |
||
| 183 | 'required' => false, |
||
| 184 | ]) |
||
| 185 | ->add('delete', SubmitType::class, [ |
||
| 186 | 'label' => $this->__('Delete'), |
||
| 187 | 'icon' => 'fa-trash-o', |
||
| 188 | 'attr' => [ |
||
| 189 | 'class' => 'btn btn-danger' |
||
| 190 | ] |
||
| 191 | ]) |
||
| 192 | ->add('cancel', SubmitType::class, [ |
||
| 193 | 'label' => $this->__('Cancel'), |
||
| 194 | 'icon' => 'fa-times', |
||
| 195 | 'attr' => [ |
||
| 196 | 'class' => 'btn btn-default' |
||
| 197 | ] |
||
| 198 | ]) |
||
| 199 | ->getForm(); |
||
| 200 | |||
| 201 | if ($form->handleRequest($request)->isValid()) { |
||
| 202 | if ($form->get('delete')->isClicked()) { |
||
| 203 | $data = $form->getData(); |
||
| 204 | $themeEntity = $this->getDoctrine()->getRepository('ZikulaThemeModule:ThemeEntity')->findOneBy(['name' => $themeName]); |
||
| 205 | if (empty($themeEntity)) { |
||
| 206 | throw new NotFoundHttpException($this->__('Sorry! No such theme found.'), null, 404); |
||
| 207 | } |
||
| 208 | if ($data['deletefiles']) { |
||
| 209 | $fs = new Filesystem(); |
||
| 210 | $path = realpath($this->get('kernel')->getRootDir() . '/../themes/' . $themeEntity->getDirectory()); |
||
| 211 | try { |
||
| 212 | // attempt to delete files |
||
| 213 | $fs->remove($path); |
||
| 214 | $this->addFlash('status', $this->__('Files removed as requested.')); |
||
| 215 | } catch (IOException $e) { |
||
|
1 ignored issue
–
show
|
|||
| 216 | $this->addFlash('danger', $this->__('Could not remove files as requested.') . ' (' . $e->getMessage() . ') ' . $this->__('The files must be removed manually.')); |
||
| 217 | } |
||
| 218 | } |
||
| 219 | // remove theme |
||
| 220 | $this->getDoctrine()->getManager()->remove($themeEntity); |
||
| 221 | // remove any theme vars |
||
| 222 | $vars = $this->get('zikula_extensions_module.api.variable')->getAll($themeName); |
||
| 223 | foreach ($vars as $var) { |
||
| 224 | $this->getDoctrine()->getManager()->remove($var); |
||
| 225 | } |
||
| 226 | $this->getDoctrine()->getManager()->flush(); |
||
| 227 | // clear all caches |
||
| 228 | $this->get('zikula.cache_clearer')->clear('twig'); |
||
| 229 | $this->get('zikula.cache_clearer')->clear('symfony.config'); |
||
| 230 | $this->addFlash('status', $data['deletefiles'] ? $this->__('Done! Deleted the theme.') : $this->__('Done! Deactivated the theme.')); |
||
| 231 | } |
||
| 232 | if ($form->get('cancel')->isClicked()) { |
||
| 233 | $this->addFlash('status', $this->__('Operation cancelled.')); |
||
| 234 | } |
||
| 235 | |||
| 236 | return $this->redirectToRoute('zikulathememodule_theme_view'); |
||
| 237 | } |
||
| 238 | |||
| 239 | return [ |
||
| 240 | 'themeName' => $themeName, |
||
| 241 | 'form' => $form->createView() |
||
| 242 | ]; |
||
| 243 | } |
||
| 244 | |||
| 269 |
Scrutinizer analyzes your
composer.json/composer.lockfile if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.