Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 18 | class ViewHelperNode extends AbstractNode |
||
| 19 | { |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $viewHelperClassName; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var NodeInterface[] |
||
| 28 | */ |
||
| 29 | protected $arguments = []; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var ViewHelperInterface |
||
| 33 | */ |
||
| 34 | protected $uninitializedViewHelper = null; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var ArgumentDefinition[] |
||
| 38 | */ |
||
| 39 | protected $argumentDefinitions = []; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | protected $pointerTemplateCode = null; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var string |
||
| 48 | */ |
||
| 49 | protected $namespace = ''; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | protected $identifier = ''; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var RenderingContextInterface |
||
| 58 | */ |
||
| 59 | protected $renderingContext; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Constructor. |
||
| 63 | * |
||
| 64 | * @param RenderingContextInterface $renderingContext a RenderingContext, provided by invoker |
||
| 65 | * @param string $namespace the namespace identifier of the ViewHelper. |
||
| 66 | * @param string $identifier the name of the ViewHelper to render, inside the namespace provided. |
||
| 67 | * @param NodeInterface[] $arguments Arguments of view helper - each value is a RootNode. |
||
| 68 | * @param ParsingState $state |
||
| 69 | */ |
||
| 70 | public function __construct(RenderingContextInterface $renderingContext, $namespace, $identifier, array $arguments, ParsingState $state) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Returns the attached (but still uninitialized) ViewHelper for this ViewHelperNode. |
||
| 89 | * We need this method because sometimes Interceptors need to ask some information from the ViewHelper. |
||
| 90 | * |
||
| 91 | * @return ViewHelperInterface |
||
| 92 | */ |
||
| 93 | public function getUninitializedViewHelper() |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Get class name of view helper |
||
| 100 | * |
||
| 101 | * @return string Class Name of associated view helper |
||
| 102 | */ |
||
| 103 | public function getViewHelperClassName() |
||
| 107 | |||
| 108 | /** |
||
| 109 | * INTERNAL - only needed for compiling templates |
||
| 110 | * |
||
| 111 | * @return NodeInterface[] |
||
| 112 | */ |
||
| 113 | public function getArguments() |
||
| 117 | |||
| 118 | /** |
||
| 119 | * INTERNAL - only needed for compiling templates |
||
| 120 | * |
||
| 121 | * @return NodeInterface[] |
||
| 122 | */ |
||
| 123 | public function getParsedArguments() |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @param NodeInterface $childNode |
||
| 130 | * @return self |
||
| 131 | */ |
||
| 132 | public function addChildNode(NodeInterface $childNode) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @param string $pointerTemplateCode |
||
| 141 | * @return void |
||
| 142 | */ |
||
| 143 | public function setPointerTemplateCode($pointerTemplateCode) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Call the view helper associated with this object. |
||
| 150 | * |
||
| 151 | * First, it evaluates the arguments of the view helper. |
||
| 152 | * |
||
| 153 | * If the view helper implements \TYPO3Fluid\Fluid\Core\ViewHelper\ChildNodeAccessInterface, |
||
| 154 | * it calls setChildNodes(array childNodes) on the view helper. |
||
| 155 | * |
||
| 156 | * Afterwards, checks that the view helper did not leave a variable lying around. |
||
| 157 | * |
||
| 158 | * @param RenderingContextInterface $renderingContext |
||
| 159 | * @return string evaluated node after the view helper has been called. |
||
| 160 | */ |
||
| 161 | public function evaluate(RenderingContextInterface $renderingContext) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Wraps the argument tree, if a node is boolean, into a Boolean syntax tree node |
||
| 168 | * |
||
| 169 | * @param ArgumentDefinition[] $argumentDefinitions the argument definitions, key is the argument name, value is the ArgumentDefinition object |
||
| 170 | * @param NodeInterface[] $argumentsObjectTree the arguments syntax tree, key is the argument name, value is an AbstractNode |
||
| 171 | * @return void |
||
| 172 | */ |
||
| 173 | protected function rewriteBooleanNodesInArgumentsObjectTree($argumentDefinitions, &$argumentsObjectTree) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @param ArgumentDefinition[] $argumentDefinitions |
||
| 192 | * @param NodeInterface[] $argumentsObjectTree |
||
| 193 | * @throws Exception |
||
| 194 | */ |
||
| 195 | View Code Duplication | protected function validateArguments(array $argumentDefinitions, array $argumentsObjectTree) |
|
| 206 | |||
| 207 | /** |
||
| 208 | * Throw an exception if required arguments are missing |
||
| 209 | * |
||
| 210 | * @param ArgumentDefinition[] $expectedArguments Array of all expected arguments |
||
| 211 | * @param NodeInterface[] $actualArguments Actual arguments |
||
| 212 | * @throws Exception |
||
| 213 | */ |
||
| 214 | protected function abortIfRequiredArgumentsAreMissing($expectedArguments, $actualArguments) |
||
| 223 | } |
||
| 224 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.