Block   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 21 2
A __destruct() 0 4 1
1
<?php
2
3
namespace Faulancer\View\Helper;
4
5
use Faulancer\View\AbstractViewHelper;
6
7
/**
8
 * Class Block
9
 *
10
 * @package Faulancer\View\Helper
11
 * @author  Florian Knapp <[email protected]>
12
 */
13
class Block extends AbstractViewHelper
14
{
15
16
    /** @var bool */
17
    protected static $tagOpened = false;
18
    protected static $content   = '';
19
20
    /**
21
     * Block opening handler
22
     *
23
     * @param string $name
24
     */
25
    public function __invoke(string $name = '')
26
    {
27
        if (!self::$tagOpened) {
28
29
            ob_start(function($buffer) {
30
                self::$content = $buffer;
31
            });
32
33
        } else {
34
35
            $content = ob_get_contents();
36
            ob_end_clean();
37
38
            $this->view->getParentTemplate()->setVariable($name, $content);
39
40
            self::$tagOpened = false;
41
42
        }
43
44
        self::$tagOpened = true;
45
    }
46
47
    public function __destruct()
48
    {
49
        self::$tagOpened = false;
50
    }
51
52
}