Completed
Pull Request — master (#429)
by Claus
01:56
created

ArgumentViewHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 30
loc 30
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeArguments() 5 5 1
A renderStatic() 9 9 2

How to fix   Duplicated Code   

Duplicated Code

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
2
namespace TYPO3Fluid\Fluid\ViewHelpers;
3
4
/*
5
 * This file belongs to the package "TYPO3 Fluid".
6
 * See LICENSE.txt that was shipped with this package.
7
 */
8
9
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
10
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
11
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
12
13
/**
14
 * Argument assigning ViewHelper
15
 *
16
 * Assigns an argument for a parent ViewHelper call when
17
 * the parent ViewHelper supports it.
18
 *
19
 * Alternative to declaring an array to pass as "arguments".
20
 *
21
 * Usages:
22
 *
23
 *     <f:render partial="Foo">
24
 *         <f:argument name="arg1">Value1</f:argument>
25
 *         <f:argument name="arg2">Value2</f:argument>
26
 *     </f:render>
27
 *
28
 * Which is the equivalent of:
29
 *
30
 *     <f:render partial="Foo" arguments="{arg1: 'Value1', arg2: 'Value2'}'" />
31
 *
32
 * But has the benefit that writing ViewHelper expressions or
33
 * other more complex syntax becomes much easier because you
34
 * can use tag syntax (tag content becomes argument value).
35
 *
36
 * @api
37
 */
38 View Code Duplication
class ArgumentViewHelper extends AbstractViewHelper
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
{
40
    use CompileWithContentArgumentAndRenderStatic;
41
42
    /**
43
     * @return void
44
     */
45
    public function initializeArguments()
46
    {
47
        $this->registerArgument('value', 'mixed', 'Value to assign. If not in arguments then taken from tag content');
48
        $this->registerArgument('name', 'string', 'Name of variable to create', true);
49
    }
50
51
    /**
52
     * @param array $arguments
53
     * @param \Closure $renderChildrenClosure
54
     * @param RenderingContextInterface $renderingContext
55
     * @return null
56
     */
57
    public static function renderStatic(
58
        array $arguments,
59
        \Closure $renderChildrenClosure,
60
        RenderingContextInterface $renderingContext
61
    ) {
62
        if ($delegateVariableProvider = $renderingContext->getViewHelperVariableContainer()->getTopmostDelegateVariableProvider()) {
63
            $delegateVariableProvider->add($arguments['name'], $renderChildrenClosure());
64
        }
65
    }
66
67
}
68