| Conditions | 10 |
| Paths | 20 |
| Total 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 |
||
| 86 | private function validInstall($entityNew, $form, ObjectManager $etm, $number, $entityName) |
||
| 87 | { |
||
| 88 | $options = []; |
||
| 89 | $return = ''; |
||
| 90 | if ('Settings\Diverse\Material' === $entityName) { |
||
| 91 | $articles = $etm->getRepository('App:Settings\Article')->findAll(); |
||
| 92 | $options = ['articles' => $articles]; |
||
| 93 | } |
||
| 94 | $etm->persist($entityNew); |
||
| 95 | $etm->flush(); |
||
| 96 | if (is_numeric($number)) { |
||
| 97 | $this->addFlash('info', 'gestock.install.st'.$number.'.flash'); |
||
| 98 | } else { |
||
| 99 | $this->addFlash('info', 'gestock.install.st5.flash'); |
||
| 100 | } |
||
| 101 | |||
| 102 | if (null !== $form->get('save') || null !== $form->get('addmore')) { |
||
| 103 | if ($form->get('save')->isClicked() && is_numeric($number)) { |
||
| 104 | $numberNext = $number++; |
||
| 105 | $return = $this->redirect($this->generateUrl('gs_install_st'.$numberNext, $options)); |
||
| 106 | } elseif ($form->get('save')->isClicked() && !is_numeric($number)) { |
||
| 107 | $return = $this->redirect($this->generateUrl('gs_install_st5')); |
||
| 108 | } elseif ($form->get('addmore')->isClicked()) { |
||
| 109 | $return = $this->redirect($this->generateUrl('gs_install_st'.$number, $options)); |
||
| 110 | } |
||
| 111 | } else { |
||
| 112 | $return = $this->redirect($this->generateUrl('gs_install_st'.$number, $options)); |
||
| 113 | } |
||
| 114 | |||
| 115 | return $return; |
||
| 116 | } |
||
| 117 | |||
| 133 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.