SlotViewHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeArguments() 0 7 1
A render() 0 4 1
A renderStatic() 0 14 2
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 FormZ project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\ViewHelpers;
15
16
use Romm\Formz\Core\Core;
17
use Romm\Formz\Exceptions\ContextNotFoundException;
18
use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService;
19
use Romm\Formz\Service\ViewHelper\Slot\SlotViewHelperService;
20
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
21
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
22
23
/**
24
 * This view helper registers a slot which will not be rendered directly, but
25
 * with the usage of the `slot.render` view helper.
26
 *
27
 * It is used to manage dynamic parts of the layouts used with the `field` view
28
 * helper: every layout can call as many slots as it needs, and this slots must
29
 * then be registered using this view helper.
30
 */
31
class SlotViewHelper extends AbstractViewHelper implements CompilableInterface
32
{
33
    /**
34
     * @inheritdoc
35
     */
36
    public function initializeArguments()
37
    {
38
        parent::initializeArguments();
39
40
        $this->registerArgument('name', 'string', 'Name of the slot.', true);
41
        $this->registerArgument('arguments', 'array', 'Arguments sent to the slot.', false, []);
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function render()
48
    {
49
        return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
0 ignored issues
show
Compatibility introduced by
$this->renderingContext of type object<TYPO3Fluid\Fluid\...deringContextInterface> is not a sub-type of object<TYPO3\CMS\Fluid\C...deringContextInterface>. It seems like you assume a child interface of the interface TYPO3Fluid\Fluid\Core\Re...nderingContextInterface to be always present.

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.

Loading history...
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55
    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
56
    {
57
        /** @var FieldViewHelperService $fieldService */
58
        $fieldService = Core::instantiate(FieldViewHelperService::class);
59
60
        if (false === $fieldService->fieldContextExists()) {
61
            throw ContextNotFoundException::slotViewHelperFieldContextNotFound();
62
        }
63
64
        /** @var SlotViewHelperService $slotService */
65
        $slotService = Core::instantiate(SlotViewHelperService::class);
66
67
        $slotService->addSlot($arguments['name'], $renderChildrenClosure, $arguments['arguments']);
68
    }
69
}
70