Completed
Pull Request — master (#404)
by Claus
02:18
created

CompileWithContentArgumentAndRenderStatic::compile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 5
dl 0
loc 28
rs 9.472
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
     * Default render method to render ViewHelper with
25
     * first defined optional argument as content.
26
     *
27
     * @return string Rendered string
28
     * @api
29
     */
30
    public function render()
31
    {
32
        return static::renderStatic(
0 ignored issues
show
Bug introduced by
The method renderStatic() does not exist on TYPO3Fluid\Fluid\Core\Vi...ArgumentAndRenderStatic. Did you maybe mean render()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
33
            $this->arguments,
0 ignored issues
show
Bug introduced by
The property arguments 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...
34
            $this->buildRenderChildrenClosure(),
0 ignored issues
show
Bug introduced by
The method buildRenderChildrenClosure() does not exist on TYPO3Fluid\Fluid\Core\Vi...ArgumentAndRenderStatic. Did you maybe mean render()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
35
            $this->renderingContext
0 ignored issues
show
Bug introduced by
The property renderingContext 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...
36
        );
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    protected function resolveContentArgumentName()
43
    {
44
        if (empty($this->contentArgumentName)) {
45
            $registeredArguments = call_user_func_array([$this, 'prepareArguments'], []);
46
            foreach ($registeredArguments as $registeredArgument) {
47
                if (!$registeredArgument->isRequired()) {
48
                    $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...
49
                    return $this->contentArgumentName;
50
                }
51
            }
52
            throw new Exception(
53
                sprintf('Attempting to compile %s failed. Chosen compile method requires that ViewHelper has ' .
54
                'at least one registered and optional argument', __CLASS__)
55
            );
56
        }
57
        return $this->contentArgumentName;
58
    }
59
}
60