Complex classes like TemplateParser often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TemplateParser, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 25 | class TemplateParser | ||
| 26 | { | ||
| 27 | |||
| 28 | /** | ||
| 29 | * The following two constants are used for tracking whether we are currently | ||
| 30 | * parsing ViewHelper arguments or not. This is used to parse arrays only as | ||
| 31 | * ViewHelper argument. | ||
| 32 | */ | ||
| 33 | const CONTEXT_INSIDE_VIEWHELPER_ARGUMENTS = 1; | ||
| 34 | const CONTEXT_OUTSIDE_VIEWHELPER_ARGUMENTS = 2; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * Whether or not the escaping interceptors are active | ||
| 38 | * | ||
| 39 | * @var boolean | ||
| 40 | */ | ||
| 41 | protected $escapingEnabled = true; | ||
| 42 | |||
| 43 | /** | ||
| 44 | * @var Configuration | ||
| 45 | */ | ||
| 46 | protected $configuration; | ||
| 47 | |||
| 48 | /** | ||
| 49 | * @var array | ||
| 50 | */ | ||
| 51 | protected $settings; | ||
| 52 | |||
| 53 | /** | ||
| 54 | * @var RenderingContextInterface | ||
| 55 | */ | ||
| 56 | protected $renderingContext; | ||
| 57 | |||
| 58 | /** | ||
| 59 | * @var integer | ||
| 60 | */ | ||
| 61 | protected $pointerLineNumber = 1; | ||
| 62 | |||
| 63 | /** | ||
| 64 | * @var integer | ||
| 65 | */ | ||
| 66 | protected $pointerLineCharacter = 1; | ||
| 67 | |||
| 68 | /** | ||
| 69 | * @var string | ||
| 70 | */ | ||
| 71 | protected $pointerTemplateCode = null; | ||
| 72 | |||
| 73 | /** | ||
| 74 | * @var ParsedTemplateInterface[] | ||
| 75 | */ | ||
| 76 | protected $parsedTemplates = []; | ||
| 77 | |||
| 78 | /** | ||
| 79 | * @param RenderingContextInterface $renderingContext | ||
| 80 | * @return void | ||
| 81 | */ | ||
| 82 | public function setRenderingContext(RenderingContextInterface $renderingContext) | ||
| 83 |     { | ||
| 84 | $this->renderingContext = $renderingContext; | ||
| 85 | $this->configuration = $renderingContext->buildParserConfiguration(); | ||
| 86 | } | ||
| 87 | |||
| 88 | /** | ||
| 89 | * Returns an array of current line number, character in line and reference template code; | ||
| 90 | * for extraction when catching parser-related Exceptions during parsing. | ||
| 91 | * | ||
| 92 | * @return array | ||
| 93 | */ | ||
| 94 | public function getCurrentParsingPointers() | ||
| 95 |     { | ||
| 96 | return [$this->pointerLineNumber, $this->pointerLineCharacter, $this->pointerTemplateCode]; | ||
| 97 | } | ||
| 98 | |||
| 99 | /** | ||
| 100 | * @return boolean | ||
| 101 | */ | ||
| 102 | public function isEscapingEnabled() | ||
| 103 |     { | ||
| 104 | return $this->escapingEnabled; | ||
| 105 | } | ||
| 106 | |||
| 107 | /** | ||
| 108 | * @param boolean $escapingEnabled | ||
| 109 | * @return void | ||
| 110 | */ | ||
| 111 | public function setEscapingEnabled($escapingEnabled) | ||
| 112 |     { | ||
| 113 | $this->escapingEnabled = (boolean) $escapingEnabled; | ||
| 114 | } | ||
| 115 | |||
| 116 | /** | ||
| 117 | * Parses a given template string and returns a parsed template object. | ||
| 118 | * | ||
| 119 | * The resulting ParsedTemplate can then be rendered by calling evaluate() on it. | ||
| 120 | * | ||
| 121 | * Normally, you should use a subclass of AbstractTemplateView instead of calling the | ||
| 122 | * TemplateParser directly. | ||
| 123 | * | ||
| 124 | * @param string $templateString The template to parse as a string | ||
| 125 | * @param string|null $templateIdentifier If the template has an identifying string it can be passed here to improve error reporting. | ||
| 126 | * @return ParsingState Parsed template | ||
| 127 | * @throws Exception | ||
| 128 | */ | ||
| 129 | public function parse($templateString, $templateIdentifier = null) | ||
| 130 |     { | ||
| 131 |         if (!is_string($templateString)) { | ||
| 132 |             throw new Exception('Parse requires a template string as argument, ' . gettype($templateString) . ' given.', 1224237899); | ||
| 133 | } | ||
| 134 |         try { | ||
| 135 | $this->reset(); | ||
| 136 | |||
| 137 | $templateString = $this->preProcessTemplateSource($templateString); | ||
| 138 | |||
| 139 | $splitTemplate = $this->splitTemplateAtDynamicTags($templateString); | ||
| 140 | $parsingState = $this->buildObjectTree($splitTemplate, self::CONTEXT_OUTSIDE_VIEWHELPER_ARGUMENTS); | ||
| 141 |         } catch (Exception $error) { | ||
| 142 | throw $this->createParsingRelatedExceptionWithContext($error, $templateIdentifier); | ||
| 143 | } | ||
| 144 | $this->parsedTemplates[$templateIdentifier] = $parsingState; | ||
| 145 | return $parsingState; | ||
| 146 | } | ||
| 147 | |||
| 148 | /** | ||
| 149 | * @param \Exception $error | ||
| 150 | * @param string $templateIdentifier | ||
| 151 | * @throws \Exception | ||
| 152 | */ | ||
| 153 | public function createParsingRelatedExceptionWithContext(\Exception $error, $templateIdentifier) | ||
| 171 | |||
| 172 | /** | ||
| 173 | * @param string $templateIdentifier | ||
| 174 | * @param \Closure $templateSourceClosure Closure which returns the template source if needed | ||
| 175 | * @return ParsedTemplateInterface | ||
| 176 | */ | ||
| 177 | public function getOrParseAndStoreTemplate($templateIdentifier, $templateSourceClosure) | ||
| 178 |     { | ||
| 179 | $compiler = $this->renderingContext->getTemplateCompiler(); | ||
| 180 |         if (isset($this->parsedTemplates[$templateIdentifier])) { | ||
| 181 | $parsedTemplate = $this->parsedTemplates[$templateIdentifier]; | ||
| 182 |         } elseif ($compiler->has($templateIdentifier)) { | ||
| 183 | $parsedTemplate = $compiler->get($templateIdentifier); | ||
| 184 |             if ($parsedTemplate instanceof UncompilableTemplateInterface) { | ||
| 185 | $parsedTemplate = $this->parseTemplateSource($templateIdentifier, $templateSourceClosure); | ||
| 186 | } | ||
| 187 |         } else { | ||
| 188 | $parsedTemplate = $this->parseTemplateSource($templateIdentifier, $templateSourceClosure); | ||
| 189 |             try { | ||
| 190 | $compiler->store($templateIdentifier, $parsedTemplate); | ||
|  | |||
| 191 |             } catch (StopCompilingException $stop) { | ||
| 192 | $this->renderingContext->getErrorHandler()->handleCompilerError($stop); | ||
| 193 | $parsedTemplate->setCompilable(false); | ||
| 194 | $compiler->store($templateIdentifier, $parsedTemplate); | ||
| 195 | } | ||
| 196 | } | ||
| 197 | return $parsedTemplate; | ||
| 198 | } | ||
| 199 | |||
| 200 | /** | ||
| 201 | * @param string $templateIdentifier | ||
| 202 | * @param \Closure $templateSourceClosure | ||
| 203 | * @return ParsedTemplateInterface | ||
| 204 | */ | ||
| 205 | protected function parseTemplateSource($templateIdentifier, $templateSourceClosure) | ||
| 206 |     { | ||
| 207 | $parsedTemplate = $this->parse( | ||
| 208 | $templateSourceClosure($this, $this->renderingContext->getTemplatePaths()), | ||
| 209 | $templateIdentifier | ||
| 210 | ); | ||
| 211 | $parsedTemplate->setIdentifier($templateIdentifier); | ||
| 212 | $this->parsedTemplates[$templateIdentifier] = $parsedTemplate; | ||
| 213 | return $parsedTemplate; | ||
| 214 | } | ||
| 215 | |||
| 216 | /** | ||
| 217 | * Pre-process the template source, making all registered TemplateProcessors | ||
| 218 | * do what they need to do with the template source before it is parsed. | ||
| 219 | * | ||
| 220 | * @param string $templateSource | ||
| 221 | * @return string | ||
| 222 | */ | ||
| 223 | protected function preProcessTemplateSource($templateSource) | ||
| 224 |     { | ||
| 225 |         foreach ($this->renderingContext->getTemplateProcessors() as $templateProcessor) { | ||
| 226 | $templateSource = $templateProcessor->preProcessSource($templateSource); | ||
| 227 | } | ||
| 228 | return $templateSource; | ||
| 229 | } | ||
| 230 | |||
| 231 | /** | ||
| 232 | * Resets the parser to its default values. | ||
| 233 | * | ||
| 234 | * @return void | ||
| 235 | */ | ||
| 236 | protected function reset() | ||
| 237 |     { | ||
| 238 | $this->escapingEnabled = true; | ||
| 239 | $this->pointerLineNumber = 1; | ||
| 240 | $this->pointerLineCharacter = 1; | ||
| 241 | } | ||
| 242 | |||
| 243 | /** | ||
| 244 | * Splits the template string on all dynamic tags found. | ||
| 245 | * | ||
| 246 | * @param string $templateString Template string to split. | ||
| 247 | * @return array Splitted template | ||
| 248 | */ | ||
| 249 | protected function splitTemplateAtDynamicTags($templateString) | ||
| 250 |     { | ||
| 251 | return preg_split(Patterns::$SPLIT_PATTERN_TEMPLATE_DYNAMICTAGS, $templateString, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); | ||
| 252 | } | ||
| 253 | |||
| 254 | /** | ||
| 255 | * Build object tree from the split template | ||
| 256 | * | ||
| 257 | * @param array $splitTemplate The split template, so that every tag with a namespace declaration is already a seperate array element. | ||
| 258 | * @param integer $context one of the CONTEXT_* constants, defining whether we are inside or outside of ViewHelper arguments currently. | ||
| 259 | * @return ParsingState | ||
| 260 | * @throws Exception | ||
| 261 | */ | ||
| 262 | protected function buildObjectTree(array $splitTemplate, $context) | ||
| 263 |     { | ||
| 264 | $state = $this->getParsingState(); | ||
| 265 | $previousBlock = ''; | ||
| 266 | |||
| 267 |         foreach ($splitTemplate as $templateElement) { | ||
| 268 |             if ($context === self::CONTEXT_OUTSIDE_VIEWHELPER_ARGUMENTS) { | ||
| 269 | // Store a neat reference to the outermost chunk of Fluid template code. | ||
| 270 | // Don't store the reference if parsing ViewHelper arguments object tree; | ||
| 271 | // we want the reference code to contain *all* of the ViewHelper call. | ||
| 272 | $this->pointerTemplateCode = $templateElement; | ||
| 273 | } | ||
| 274 | $this->pointerLineNumber += substr_count($templateElement, PHP_EOL); | ||
| 275 | $this->pointerLineCharacter = strlen(substr($previousBlock, strrpos($previousBlock, PHP_EOL))) + 1; | ||
| 276 | $previousBlock = $templateElement; | ||
| 277 | $matchedVariables = []; | ||
| 278 | |||
| 279 |             if (preg_match(Patterns::$SCAN_PATTERN_TEMPLATE_VIEWHELPERTAG, $templateElement, $matchedVariables) > 0) { | ||
| 280 | if ($this->openingViewHelperTagHandler( | ||
| 281 | $state, | ||
| 282 | $matchedVariables['NamespaceIdentifier'], | ||
| 283 | $matchedVariables['MethodIdentifier'], | ||
| 284 | $matchedVariables['Attributes'], | ||
| 285 | ($matchedVariables['Selfclosing'] === '' ? false : true), | ||
| 286 | $templateElement | ||
| 287 |                 )) { | ||
| 288 | continue; | ||
| 289 | } | ||
| 290 |             } elseif (preg_match(Patterns::$SCAN_PATTERN_TEMPLATE_CLOSINGVIEWHELPERTAG, $templateElement, $matchedVariables) > 0) { | ||
| 291 | if ($this->closingViewHelperTagHandler( | ||
| 292 | $state, | ||
| 293 | $matchedVariables['NamespaceIdentifier'], | ||
| 294 | $matchedVariables['MethodIdentifier'] | ||
| 295 |                 )) { | ||
| 296 | continue; | ||
| 297 | } | ||
| 298 | } | ||
| 299 | $this->textAndShorthandSyntaxHandler($state, $templateElement, $context); | ||
| 300 | } | ||
| 301 | |||
| 302 |         if ($state->countNodeStack() !== 1) { | ||
| 303 | throw new Exception( | ||
| 304 | 'Not all tags were closed!', | ||
| 305 | 1238169398 | ||
| 306 | ); | ||
| 307 | } | ||
| 308 | return $state; | ||
| 309 | } | ||
| 310 | /** | ||
| 311 | * Handles an opening or self-closing view helper tag. | ||
| 312 | * | ||
| 313 | * @param ParsingState $state Current parsing state | ||
| 314 | * @param string $namespaceIdentifier Namespace identifier - being looked up in $this->namespaces | ||
| 315 | * @param string $methodIdentifier Method identifier | ||
| 316 | * @param string $arguments Arguments string, not yet parsed | ||
| 317 | * @param boolean $selfclosing true, if the tag is a self-closing tag. | ||
| 318 | * @param string $templateElement The template code containing the ViewHelper call | ||
| 319 | * @return NodeInterface|null | ||
| 320 | */ | ||
| 321 | protected function openingViewHelperTagHandler(ParsingState $state, $namespaceIdentifier, $methodIdentifier, $arguments, $selfclosing, $templateElement) | ||
| 322 |     { | ||
| 323 | $viewHelperNode = $this->initializeViewHelperAndAddItToStack( | ||
| 324 | $state, | ||
| 325 | $namespaceIdentifier, | ||
| 326 | $methodIdentifier, | ||
| 327 | $this->parseArguments($arguments) | ||
| 328 | ); | ||
| 329 | |||
| 330 |         if ($viewHelperNode) { | ||
| 331 | $viewHelperNode->setPointerTemplateCode($templateElement); | ||
| 332 |             if ($selfclosing === true) { | ||
| 333 | $state->popNodeFromStack(); | ||
| 334 | $this->callInterceptor($viewHelperNode, InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER, $state); | ||
| 335 | // This needs to be called here because closingViewHelperTagHandler() is not triggered for self-closing tags | ||
| 336 | $state->getNodeFromStack()->addChildNode($viewHelperNode); | ||
| 337 | } | ||
| 338 | } | ||
| 339 | |||
| 340 | return $viewHelperNode; | ||
| 341 | } | ||
| 342 | |||
| 343 | /** | ||
| 344 | * Initialize the given ViewHelper and adds it to the current node and to | ||
| 345 | * the stack. | ||
| 346 | * | ||
| 347 | * @param ParsingState $state Current parsing state | ||
| 348 | * @param string $namespaceIdentifier Namespace identifier - being looked up in $this->namespaces | ||
| 349 | * @param string $methodIdentifier Method identifier | ||
| 350 | * @param array $argumentsObjectTree Arguments object tree | ||
| 351 | * @return null|NodeInterface An instance of ViewHelperNode if identity was valid - NULL if the namespace/identity was not registered | ||
| 352 | * @throws Exception | ||
| 353 | */ | ||
| 354 | protected function initializeViewHelperAndAddItToStack(ParsingState $state, $namespaceIdentifier, $methodIdentifier, $argumentsObjectTree) | ||
| 355 |     { | ||
| 356 | $viewHelperResolver = $this->renderingContext->getViewHelperResolver(); | ||
| 357 |         if (!$viewHelperResolver->isNamespaceValid($namespaceIdentifier)) { | ||
| 358 | return null; | ||
| 359 | } | ||
| 360 |         try { | ||
| 361 | $currentViewHelperNode = new ViewHelperNode( | ||
| 362 | $this->renderingContext, | ||
| 363 | $namespaceIdentifier, | ||
| 364 | $methodIdentifier, | ||
| 365 | $argumentsObjectTree, | ||
| 366 | $state | ||
| 367 | ); | ||
| 368 | |||
| 369 | $this->callInterceptor($currentViewHelperNode, InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER, $state); | ||
| 370 | $viewHelper = $currentViewHelperNode->getUninitializedViewHelper(); | ||
| 371 | $viewHelper::postParseEvent($currentViewHelperNode, $argumentsObjectTree, $state->getVariableContainer()); | ||
| 372 | $state->pushNodeToStack($currentViewHelperNode); | ||
| 373 | return $currentViewHelperNode; | ||
| 374 |         } catch (\TYPO3Fluid\Fluid\Core\ViewHelper\Exception $error) { | ||
| 375 | $this->textHandler( | ||
| 376 | $state, | ||
| 377 | $this->renderingContext->getErrorHandler()->handleViewHelperError($error) | ||
| 378 | ); | ||
| 379 |         } catch (Exception $error) { | ||
| 380 | $this->textHandler( | ||
| 381 | $state, | ||
| 382 | $this->renderingContext->getErrorHandler()->handleParserError($error) | ||
| 383 | ); | ||
| 384 | } | ||
| 385 | return null; | ||
| 386 | } | ||
| 387 | |||
| 388 | /** | ||
| 389 | * Handles a closing view helper tag | ||
| 390 | * | ||
| 391 | * @param ParsingState $state The current parsing state | ||
| 392 | * @param string $namespaceIdentifier Namespace identifier for the closing tag. | ||
| 393 | * @param string $methodIdentifier Method identifier. | ||
| 394 | * @return boolean whether the viewHelper was found and added to the stack or not | ||
| 395 | * @throws Exception | ||
| 396 | */ | ||
| 397 | protected function closingViewHelperTagHandler(ParsingState $state, $namespaceIdentifier, $methodIdentifier) | ||
| 398 |     { | ||
| 399 | $viewHelperResolver = $this->renderingContext->getViewHelperResolver(); | ||
| 400 |         if (!$viewHelperResolver->isNamespaceValid($namespaceIdentifier)) { | ||
| 401 | return false; | ||
| 402 | } | ||
| 403 | $lastStackElement = $state->popNodeFromStack(); | ||
| 404 |         if (!($lastStackElement instanceof ViewHelperNode)) { | ||
| 405 |             throw new Exception('You closed a templating tag which you never opened!', 1224485838); | ||
| 406 | } | ||
| 407 | $actualViewHelperClassName = $viewHelperResolver->resolveViewHelperClassName($namespaceIdentifier, $methodIdentifier); | ||
| 408 | $expectedViewHelperClassName = $lastStackElement->getViewHelperClassName(); | ||
| 409 |         if ($actualViewHelperClassName !== $expectedViewHelperClassName) { | ||
| 410 | throw new Exception( | ||
| 411 | 'Templating tags not properly nested. Expected: ' . $expectedViewHelperClassName . '; Actual: ' . | ||
| 412 | $actualViewHelperClassName, | ||
| 413 | 1224485398 | ||
| 414 | ); | ||
| 415 | } | ||
| 416 | $this->callInterceptor($lastStackElement, InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER, $state); | ||
| 417 | $state->getNodeFromStack()->addChildNode($lastStackElement); | ||
| 418 | |||
| 419 | return true; | ||
| 420 | } | ||
| 421 | |||
| 422 | /** | ||
| 423 |      * Handles the appearance of an object accessor (like {posts.author.email}). | ||
| 424 | * Creates a new instance of \TYPO3Fluid\Fluid\ObjectAccessorNode. | ||
| 425 | * | ||
| 426 | * Handles ViewHelpers as well which are in the shorthand syntax. | ||
| 427 | * | ||
| 428 | * @param ParsingState $state The current parsing state | ||
| 429 | * @param string $objectAccessorString String which identifies which objects to fetch | ||
| 430 | * @param string $delimiter | ||
| 431 | * @param string $viewHelperString | ||
| 432 | * @param string $additionalViewHelpersString | ||
| 433 | * @return void | ||
| 434 | */ | ||
| 435 | protected function objectAccessorHandler(ParsingState $state, $objectAccessorString, $delimiter, $viewHelperString, $additionalViewHelpersString) | ||
| 436 |     { | ||
| 437 | $viewHelperString .= $additionalViewHelpersString; | ||
| 438 | $numberOfViewHelpers = 0; | ||
| 439 | |||
| 440 | // The following post-processing handles a case when there is only a ViewHelper, and no Object Accessor. | ||
| 441 | // Resolves bug #5107. | ||
| 442 |         if (strlen($delimiter) === 0 && strlen($viewHelperString) > 0) { | ||
| 443 | $viewHelperString = $objectAccessorString . $viewHelperString; | ||
| 444 | $objectAccessorString = ''; | ||
| 445 | } | ||
| 446 | |||
| 447 | // ViewHelpers | ||
| 448 | $matches = []; | ||
| 449 |         if (strlen($viewHelperString) > 0 && preg_match_all(Patterns::$SPLIT_PATTERN_SHORTHANDSYNTAX_VIEWHELPER, $viewHelperString, $matches, PREG_SET_ORDER) > 0) { | ||
| 450 | // The last ViewHelper has to be added first for correct chaining. | ||
| 451 |             foreach (array_reverse($matches) as $singleMatch) { | ||
| 452 |                 if (strlen($singleMatch['ViewHelperArguments']) > 0) { | ||
| 453 | $arguments = $this->recursiveArrayHandler($singleMatch['ViewHelperArguments']); | ||
| 454 |                 } else { | ||
| 455 | $arguments = []; | ||
| 456 | } | ||
| 457 | $viewHelperNode = $this->initializeViewHelperAndAddItToStack($state, $singleMatch['NamespaceIdentifier'], $singleMatch['MethodIdentifier'], $arguments); | ||
| 458 |                 if ($viewHelperNode) { | ||
| 459 | $numberOfViewHelpers++; | ||
| 460 | } | ||
| 461 | } | ||
| 462 | } | ||
| 463 | |||
| 464 | // Object Accessor | ||
| 465 |         if (strlen($objectAccessorString) > 0) { | ||
| 466 | $node = new ObjectAccessorNode($objectAccessorString); | ||
| 467 | $this->callInterceptor($node, InterceptorInterface::INTERCEPT_OBJECTACCESSOR, $state); | ||
| 468 | $state->getNodeFromStack()->addChildNode($node); | ||
| 469 | } | ||
| 470 | |||
| 471 | // Close ViewHelper Tags if needed. | ||
| 472 |         for ($i = 0; $i < $numberOfViewHelpers; $i++) { | ||
| 473 | $node = $state->popNodeFromStack(); | ||
| 474 | $this->callInterceptor($node, InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER, $state); | ||
| 475 | $state->getNodeFromStack()->addChildNode($node); | ||
| 476 | } | ||
| 477 | } | ||
| 478 | |||
| 479 | /** | ||
| 480 | * Call all interceptors registered for a given interception point. | ||
| 481 | * | ||
| 482 | * @param NodeInterface $node The syntax tree node which can be modified by the interceptors. | ||
| 483 | * @param integer $interceptionPoint the interception point. One of the \TYPO3Fluid\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_* constants. | ||
| 484 | * @param ParsingState $state the parsing state | ||
| 485 | * @return void | ||
| 486 | */ | ||
| 487 | protected function callInterceptor(NodeInterface & $node, $interceptionPoint, ParsingState $state) | ||
| 488 |     { | ||
| 489 |         if ($this->configuration === null) { | ||
| 490 | return; | ||
| 491 | } | ||
| 492 |         if ($this->escapingEnabled) { | ||
| 493 | /** @var $interceptor InterceptorInterface */ | ||
| 494 |             foreach ($this->configuration->getEscapingInterceptors($interceptionPoint) as $interceptor) { | ||
| 495 | $node = $interceptor->process($node, $interceptionPoint, $state); | ||
| 496 | } | ||
| 497 | } | ||
| 498 | |||
| 499 | /** @var $interceptor InterceptorInterface */ | ||
| 500 |         foreach ($this->configuration->getInterceptors($interceptionPoint) as $interceptor) { | ||
| 501 | $node = $interceptor->process($node, $interceptionPoint, $state); | ||
| 502 | } | ||
| 503 | } | ||
| 504 | |||
| 505 | /** | ||
| 506 | * Parse arguments of a given tag, and build up the Arguments Object Tree | ||
| 507 | * for each argument. | ||
| 508 | * Returns an associative array, where the key is the name of the argument, | ||
| 509 | * and the value is a single Argument Object Tree. | ||
| 510 | * | ||
| 511 | * @param string $argumentsString All arguments as string | ||
| 512 | * @return array An associative array of objects, where the key is the argument name. | ||
| 513 | */ | ||
| 514 | protected function parseArguments($argumentsString) | ||
| 530 | |||
| 531 | /** | ||
| 532 | * Build up an argument object tree for the string in $argumentString. | ||
| 533 | * This builds up the tree for a single argument value. | ||
| 534 | * | ||
| 535 | * This method also does some performance optimizations, so in case | ||
| 536 |      * no { or < is found, then we just return a TextNode. | ||
| 537 | * | ||
| 538 | * @param string $argumentString | ||
| 539 | * @return SyntaxTree\NodeInterface the corresponding argument object tree. | ||
| 540 | */ | ||
| 541 | protected function buildArgumentObjectTree($argumentString) | ||
| 542 |     { | ||
| 543 |         if (strpos($argumentString, '{') === false && strpos($argumentString, '<') === false) { | ||
| 544 |             if (is_numeric($argumentString)) { | ||
| 545 | return new NumericNode($argumentString); | ||
| 546 | } | ||
| 553 | |||
| 554 | /** | ||
| 555 | * Removes escapings from a given argument string and trims the outermost | ||
| 556 | * quotes. | ||
| 557 | * | ||
| 558 | * This method is meant as a helper for regular expression results. | ||
| 559 | * | ||
| 560 | * @param string $quotedValue Value to unquote | ||
| 561 | * @return string Unquoted value | ||
| 562 | */ | ||
| 563 | public function unquoteString($quotedValue) | ||
| 573 | |||
| 574 | /** | ||
| 575 | * Handler for everything which is not a ViewHelperNode. | ||
| 576 | * | ||
| 577 | * This includes Text, array syntax, and object accessor syntax. | ||
| 578 | * | ||
| 579 | * @param ParsingState $state Current parsing state | ||
| 580 | * @param string $text Text to process | ||
| 581 | * @param integer $context one of the CONTEXT_* constants, defining whether we are inside or outside of ViewHelper arguments currently. | ||
| 582 | * @return void | ||
| 583 | */ | ||
| 584 | protected function textAndShorthandSyntaxHandler(ParsingState $state, $text, $context) | ||
| 646 | |||
| 647 | /** | ||
| 648 | * Handler for array syntax. This creates the array object recursively and | ||
| 649 | * adds it to the current node. | ||
| 650 | * | ||
| 651 | * @param ParsingState $state The current parsing state | ||
| 652 | * @param NodeInterface[] $arrayText The array as string. | ||
| 653 | * @return void | ||
| 654 | */ | ||
| 655 | protected function arrayHandler(ParsingState $state, $arrayText) | ||
| 660 | |||
| 661 | /** | ||
| 662 | * Recursive function which takes the string representation of an array and | ||
| 663 | * builds an object tree from it. | ||
| 664 | * | ||
| 665 | * Deals with the following value types: | ||
| 666 | * - Numbers (Integers and Floats) | ||
| 667 | * - Strings | ||
| 668 | * - Variables | ||
| 669 | * - sub-arrays | ||
| 670 | * | ||
| 671 | * @param string $arrayText Array text | ||
| 672 | * @return NodeInterface[] the array node built up | ||
| 673 | * @throws Exception | ||
| 674 | */ | ||
| 675 | protected function recursiveArrayHandler($arrayText) | ||
| 696 | |||
| 697 | /** | ||
| 698 | * Text node handler | ||
| 699 | * | ||
| 700 | * @param ParsingState $state | ||
| 701 | * @param string $text | ||
| 702 | * @return void | ||
| 703 | */ | ||
| 704 | protected function textHandler(ParsingState $state, $text) | ||
| 710 | |||
| 711 | /** | ||
| 712 | * @return ParsingState | ||
| 713 | */ | ||
| 714 | protected function getParsingState() | ||
| 724 | } | ||
| 725 | 
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.