| Conditions | 9 |
| Paths | 22 |
| Total Lines | 52 |
| Code Lines | 31 |
| 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 |
||
| 40 | public function upgradeAction(Request $request, $stage): Response |
||
| 41 | { |
||
| 42 | $currentVersion = $this->container->getParameter(ZikulaKernel::CORE_INSTALLED_VERSION_PARAM); |
||
| 43 | if (version_compare($currentVersion, ZikulaKernel::VERSION, '=')) { |
||
| 44 | $stage = 'complete'; |
||
| 45 | } |
||
| 46 | // not installed? |
||
| 47 | if (false === $this->container->getParameter('installed')) { |
||
| 48 | return new RedirectResponse($this->router->generate('install')); |
||
| 49 | } |
||
| 50 | |||
| 51 | // check php |
||
| 52 | $ini_warnings = $this->controllerHelper->initPhp(); |
||
| 53 | if (count($ini_warnings) > 0) { |
||
| 54 | $request->getSession()->getFlashBag()->add('warning', implode('<hr>', $ini_warnings)); |
||
| 55 | } |
||
| 56 | |||
| 57 | $yamlDumper = new YamlDumper($this->container->get('kernel')->getRootDir() . '/config', 'custom_parameters.yml'); |
||
| 58 | $yamlDumper->setParameter('upgrading', true); |
||
| 59 | $request->setLocale($this->container->getParameter('locale')); |
||
| 60 | |||
| 61 | // begin the wizard |
||
| 62 | $wizard = new Wizard($this->container, dirname(__DIR__) . '/Resources/config/upgrade_stages.yml'); |
||
| 63 | $currentStage = $wizard->getCurrentStage($stage); |
||
| 64 | if ($currentStage instanceof WizardCompleteInterface) { |
||
| 65 | $yamlDumper->setParameter('upgrading', false); |
||
| 66 | |||
| 67 | return $currentStage->getResponse($request); |
||
| 68 | } |
||
| 69 | $templateParams = $this->controllerHelper->getTemplateGlobals($currentStage); |
||
| 70 | $templateParams['headertemplate'] = '@ZikulaCoreInstaller/upgradeheader.html.twig'; |
||
| 71 | if ($wizard->isHalted()) { |
||
| 72 | $request->getSession()->getFlashBag()->add('danger', $wizard->getWarning()); |
||
| 73 | |||
| 74 | return $this->renderResponse('@ZikulaCoreInstaller/error.html.twig', $templateParams); |
||
| 75 | } |
||
| 76 | |||
| 77 | // handle the form |
||
| 78 | if ($currentStage instanceof FormHandlerInterface) { |
||
| 79 | $form = $this->form->create($currentStage->getFormType(), null, $currentStage->getFormOptions()); |
||
|
|
|||
| 80 | $form->handleRequest($request); |
||
| 81 | if ($form->isSubmitted() && $form->isValid()) { |
||
| 82 | $currentStage->handleFormResult($form); |
||
| 83 | $params = ['stage' => $wizard->getNextStage()->getName(), '_locale' => $this->container->getParameter('locale')]; |
||
| 84 | $url = $this->router->generate('upgrade', $params); |
||
| 85 | |||
| 86 | return new RedirectResponse($url); |
||
| 87 | } |
||
| 88 | $templateParams['form'] = $form->createView(); |
||
| 89 | } |
||
| 90 | |||
| 91 | return $this->renderResponse($currentStage->getTemplateName(), $templateParams); |
||
| 92 | } |
||
| 94 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.