| Conditions | 8 |
| Paths | 42 |
| Total Lines | 63 |
| Code Lines | 42 |
| 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 |
||
| 56 | public function render(WizardContainer $container, $layout = Form::LAYOUT_HORIZONTAL, $parameter = array()) |
||
| 57 | { |
||
| 58 | |||
| 59 | $content = ''; |
||
| 60 | |||
| 61 | $content .= $container->renderPre($this->getView()); |
||
| 62 | |||
| 63 | $tabsNav = ''; |
||
| 64 | $tabsContent = ''; |
||
| 65 | $containerParams = [ |
||
| 66 | 'pager' => true, |
||
| 67 | 'finish_label' => 'Finish', |
||
| 68 | 'finish_href' => 'javascript:;', |
||
| 69 | 'finish_enabled' => true, |
||
| 70 | ]; |
||
| 71 | |||
| 72 | if (isset($parameter['wizard'])) { |
||
| 73 | $containerParams = array_merge($containerParams, $parameter['wizard']); |
||
| 74 | unset($parameter['wizard']); |
||
| 75 | } |
||
| 76 | |||
| 77 | $translate = $this->getView()->plugin('translate'); |
||
| 78 | $formContainer = $this->getView()->plugin('formcontainer'); |
||
| 79 | |||
| 80 | if ($container instanceof ViewPartialProviderInterface) { |
||
| 81 | return $this->getView()->partial($container->getViewPartial(), array('element' => $container)); |
||
| 82 | } |
||
| 83 | |||
| 84 | $containerId = $container->getAttribute('id'); |
||
| 85 | if (!$containerId) { |
||
| 86 | $containerId = 'wizardcontainer-' . strtolower(str_replace('\\', '-', get_class($container))); |
||
| 87 | } |
||
| 88 | |||
| 89 | foreach ($container as $tabElement) { |
||
| 90 | $tabId = $containerId . '-' . strtolower($tabElement->getName()); |
||
| 91 | $tabsNav .= '<li><a data-toggle="tab" href="#' . $tabId . '">' . $translate($tabElement->getLabel()) . '</a></li>'; |
||
| 92 | $tabsContent .= '<div class="tab-pane" id="' . $tabId . '">' |
||
| 93 | . $formContainer($tabElement, $layout, $parameter) |
||
| 94 | . '</div>'; |
||
| 95 | } |
||
| 96 | |||
| 97 | $content .= '<style type="text/css">.tab-content > div > div:first-child { margin-top: 10px; }</style><div class="wizard-container" id="' . $containerId . '">' |
||
| 98 | . '<ul>' . $tabsNav . '</ul>' |
||
| 99 | . '<div class="tab-content">' . $tabsContent . '</div>'; |
||
| 100 | if ($containerParams['pager']) { |
||
| 101 | $content .='<ul class="pager wizard">' |
||
| 102 | . '<li class="previous"><a href="javascript:;">← ' . $translate('previous') . '</a></li>' |
||
| 103 | . '<li class="next"><a href="javascript:;">' . $translate('Next') . ' →</a></li>' |
||
| 104 | . '<li class="finish' . ($containerParams['finish_enabled'] ? '' : ' disabled') . '">' |
||
| 105 | . (false !== $containerParams['finish_label'] |
||
| 106 | ? '<a class="pull-right" href="' . $containerParams['finish_href'] . '">' |
||
| 107 | . $translate($containerParams['finish_label']) . ' •</a>' |
||
| 108 | : '' |
||
| 109 | ) |
||
| 110 | . '</li></ul>'; |
||
| 111 | } |
||
| 112 | $content .= '</div>'; |
||
| 113 | |||
| 114 | $content .= $container->renderPost($this->getView()); |
||
| 115 | |||
| 116 | return $content; |
||
| 117 | |||
| 118 | } |
||
| 119 | } |
||
| 120 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: