Completed
Push — development ( 9be619...e22509 )
by Romain
02:55
created

SlotViewHelperService   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 99
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A activate() 0 4 1
A resetState() 0 4 1
A addSlot() 0 4 1
A getSlotClosure() 0 4 1
A getSlotArguments() 0 4 1
A hasSlot() 0 4 1
A addTemplateVariables() 0 4 1
A restoreTemplateVariables() 0 4 1
A getCurrentContext() 0 4 1
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\Service\ViewHelper\Slot;
15
16
use Closure;
17
use Romm\Formz\Exceptions\EntryNotFoundException;
18
use TYPO3\CMS\Core\SingletonInterface;
19
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
21
22
class SlotViewHelperService implements SingletonInterface
23
{
24
    /**
25
     * @var SlotContextEntry[]
26
     */
27
    protected $contextEntries = [];
28
29
    /**
30
     * @param RenderingContextInterface $renderingContext
31
     */
32
    public function activate(RenderingContextInterface $renderingContext)
33
    {
34
        $this->contextEntries[] = GeneralUtility::makeInstance(SlotContextEntry::class, $renderingContext);
35
    }
36
37
    /**
38
     * Removes the current context entry.
39
     */
40
    public function resetState()
41
    {
42
        array_pop($this->contextEntries);
43
    }
44
45
    /**
46
     * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::addSlot()
47
     *
48
     * @param string  $name
49
     * @param Closure $closure
50
     * @param array   $arguments
51
     */
52
    public function addSlot($name, Closure $closure, array $arguments)
53
    {
54
        $this->getCurrentContext()->addSlot($name, $closure, $arguments);
55
    }
56
57
    /**
58
     * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::getSlotClosure()
59
     *
60
     * @param string $name
61
     * @return Closure
62
     * @throws EntryNotFoundException
63
     */
64
    public function getSlotClosure($name)
65
    {
66
        return $this->getCurrentContext()->getSlotClosure($name);
67
    }
68
69
    /**
70
     * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::getSlotArguments()
71
     *
72
     * @param string $name
73
     * @return array
74
     * @throws EntryNotFoundException
75
     */
76
    public function getSlotArguments($name)
77
    {
78
        return $this->getCurrentContext()->getSlotArguments($name);
79
    }
80
81
    /**
82
     * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::hasSlot()
83
     *
84
     * @param string $name
85
     * @return bool
86
     */
87
    public function hasSlot($name)
88
    {
89
        return $this->getCurrentContext()->hasSlot($name);
90
    }
91
92
    /**
93
     * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::addTemplateVariables()
94
     *
95
     * @param string $slotName
96
     * @param array  $arguments
97
     */
98
    public function addTemplateVariables($slotName, array $arguments)
99
    {
100
        $this->getCurrentContext()->addTemplateVariables($slotName, $arguments);
101
    }
102
103
    /**
104
     * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::restoreTemplateVariables()
105
     *
106
     * @param string $slotName
107
     */
108
    public function restoreTemplateVariables($slotName)
109
    {
110
        $this->getCurrentContext()->restoreTemplateVariables($slotName);
111
    }
112
113
    /**
114
     * @return SlotContextEntry
115
     */
116
    protected function getCurrentContext()
117
    {
118
        return end($this->contextEntries);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression end($this->contextEntries); of type Romm\Formz\Service\ViewH...\SlotContextEntry|false adds false to the return on line 118 which is incompatible with the return type documented by Romm\Formz\Service\ViewH...vice::getCurrentContext of type Romm\Formz\Service\ViewH...r\Slot\SlotContextEntry. It seems like you forgot to handle an error condition.
Loading history...
119
    }
120
}
121