Conditions | 11 |
Paths | 36 |
Total Lines | 49 |
Code Lines | 36 |
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 |
||
116 | public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) |
||
117 | { |
||
118 | $section = $arguments['section']; |
||
119 | $partial = $arguments['partial']; |
||
120 | $variables = (array) $arguments['arguments']; |
||
121 | $optional = (boolean) $arguments['optional']; |
||
122 | $delegate = $arguments['delegate']; |
||
123 | /** @var RenderableInterface $renderable */ |
||
124 | $renderable = $arguments['renderable']; |
||
125 | $tagContent = $renderChildrenClosure(); |
||
126 | if ($arguments['contentAs']) { |
||
127 | $variables[$arguments['contentAs']] = $tagContent; |
||
128 | } |
||
129 | |||
130 | $view = $renderingContext->getViewHelperVariableContainer()->getView(); |
||
131 | if (!$view) { |
||
132 | throw new Exception( |
||
133 | 'The f:render ViewHelper was used in a context where the ViewHelperVariableContainer does not contain ' . |
||
134 | 'a reference to the View. Normally this is taken care of by the TemplateView, so most likely this ' . |
||
135 | 'error is because you overrode AbstractTemplateView->initializeRenderingContext() and did not call ' . |
||
136 | '$renderingContext->getViewHelperVariableContainer()->setView($this) or parent::initializeRenderingContext. ' . |
||
137 | 'This is an issue you must fix in your code as f:render is fully unable to render anything without a View.' |
||
138 | ); |
||
139 | } |
||
140 | $content = ''; |
||
141 | if ($renderable) { |
||
142 | $content = $renderable->render($renderingContext); |
||
143 | } elseif ($delegate !== null) { |
||
144 | if (!is_a($delegate, ParsedTemplateInterface::class, true)) { |
||
145 | throw new \InvalidArgumentException(sprintf('Cannot render %s - must implement ParsedTemplateInterface!', $delegate)); |
||
146 | } |
||
147 | $renderingContext = clone $renderingContext; |
||
148 | $renderingContext->getVariableProvider()->setSource($variables); |
||
149 | $content = (new $delegate())->render($renderingContext); |
||
150 | } elseif ($partial !== null) { |
||
151 | $content = $view->renderPartial($partial, $section, $variables, $optional); |
||
152 | } elseif ($section !== null) { |
||
153 | $content = $view->renderSection($section, $variables, $optional); |
||
154 | } elseif (!$optional) { |
||
155 | throw new \InvalidArgumentException('ViewHelper f:render called without either argument section, partial, renderable or delegate and optional flag is false'); |
||
156 | } |
||
157 | // Replace empty content with default value. If default is |
||
158 | // not set, NULL is returned and cast to a new, empty string |
||
159 | // outside of this ViewHelper. |
||
160 | if ($content === '') { |
||
161 | $content = $arguments['default'] ?: $tagContent; |
||
162 | } |
||
163 | return $content; |
||
164 | } |
||
165 | } |
||
166 |