| Conditions | 14 |
| Paths | 26 |
| Total Lines | 46 |
| Code Lines | 41 |
| 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 |
||
| 89 | protected function resolveAndSetTemplatePathIfCan(RenderableInterface $item) |
||
| 90 | { |
||
| 91 | $templatePath = ""; |
||
| 92 | switch (true) { |
||
| 93 | case $item instanceof ClassManager: |
||
| 94 | $templatePath = $item->getClassManagerTemplatePath(); |
||
| 95 | break; |
||
| 96 | case $item instanceof PropertyManager: |
||
| 97 | $templatePath = $item->getPropertyManagerTemplatePath(); |
||
| 98 | break; |
||
| 99 | case $item instanceof ClassConstructorManager: |
||
| 100 | $templatePath = $item->getClassManager()->getClassConstructorManagerTemplatePath(); |
||
| 101 | break; |
||
| 102 | case $item instanceof InterfaceManager: |
||
| 103 | $templatePath = $item->getClassManager()->getInterfaceManagerTemplatePath(); |
||
| 104 | break; |
||
| 105 | case $item instanceof TestClassManager: |
||
| 106 | $templatePath = $item->getClassManager()->getTestClassManagerTemplatePath(); |
||
| 107 | break; |
||
| 108 | case $item instanceof TestMethodManager: |
||
| 109 | $templatePath = $item->getMethod()->getProperty()->getTestClassMethodManagerTemplatePath(); |
||
| 110 | break; |
||
| 111 | case $item instanceof MethodGetterManager: |
||
| 112 | $templatePath = $item->getProperty()->getMethodGetterManagerTemplatePath(); |
||
| 113 | break; |
||
| 114 | case $item instanceof MethodGetterInterfaceManager: |
||
| 115 | $templatePath = $item->getProperty()->getMethodGetterInterfaceManagerTemplatePath(); |
||
| 116 | break; |
||
| 117 | case $item instanceof MethodGetterBooleanManager: |
||
| 118 | $templatePath = $item->getProperty()->getMethodGetterBooleanManagerTemplatePath(); |
||
| 119 | break; |
||
| 120 | case $item instanceof MethodGetterBooleanInterfaceManager: |
||
| 121 | $templatePath = $item->getProperty()->getMethodGetterBooleanInterfaceManageTemplatePath(); |
||
| 122 | break; |
||
| 123 | case $item instanceof MethodSetterInterfaceManager: |
||
| 124 | $templatePath = $item->getProperty()->getMethodSetterInterfaceManagerTemplatePath(); |
||
| 125 | break; |
||
| 126 | case $item instanceof MethodSetterManager: |
||
| 127 | $templatePath = $item->getProperty()->getMethodSetterManagerTemplatePath(); |
||
| 128 | break; |
||
| 129 | } |
||
| 130 | |||
| 131 | if (false === empty($templatePath)) { |
||
| 132 | $item->setTemplatePath($templatePath); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.