Completed
Pull Request — master (#404)
by Claus
02:56 queued 48s
created

CompileWithContentArgumentAndRenderStatic::buildRenderChildrenClosure()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 0
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
namespace TYPO3Fluid\Fluid\Core\ViewHelper\Traits;
3
4
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
5
use TYPO3Fluid\Fluid\Core\Compiler\ViewHelperCompiler;
6
use TYPO3Fluid\Fluid\Core\Exception;
7
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
8
9
/**
10
 * Class CompilableWithContentArgumentAndRenderStatic
11
 *
12
 * Provides default methods for rendering and compiling
13
 * any ViewHelper that conforms to the `renderStatic`
14
 * method pattern but has the added common use case that
15
 * an argument value must be checked and used instead of
16
 * the normal render children closure, if that named
17
 * argument is specified and not empty.
18
 *
19
 * @deprecated Trait no longer required, content argument supported by any VH via base class.
20
 */
21
trait CompileWithContentArgumentAndRenderStatic
22
{
23
    /**
24
     * @return string
25
     */
26
    protected function resolveContentArgumentName()
27
    {
28
        if (empty($this->contentArgumentName)) {
29
            $registeredArguments = call_user_func_array([$this, 'prepareArguments'], []);
30
            foreach ($registeredArguments as $registeredArgument) {
31
                if (!$registeredArgument->isRequired()) {
32
                    $this->contentArgumentName = $registeredArgument->getName();
0 ignored issues
show
Bug introduced by
The property contentArgumentName does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
                    return $this->contentArgumentName;
34
                }
35
            }
36
            throw new Exception(
37
                sprintf('Attempting to compile %s failed. Chosen compile method requires that ViewHelper has ' .
38
                'at least one registered and optional argument', __CLASS__)
39
            );
40
        }
41
        return $this->contentArgumentName;
42
    }
43
}
44