WithDirective::pop()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Bavix\Flow\Directives;
4
5
use Bavix\Flow\Directive;
6
use Bavix\Helpers\Arr;
7
8
class WithDirective extends Directive
9
{
10
11
    protected static $index   = 0;
12
    protected static $storage = [];
13
14 1
    protected static function calc()
15
    {
16 1
        static::$index = \count(static::$storage) - 1;
17 1
    }
18
19 1
    public static function &last()
20
    {
21 1
        return static::$storage[static::$index];
22
    }
23
24
    public static function pushObject($data)
25
    {
26
        static::$storage[] = $data;
27
        static::calc();
28
    }
29
30 1
    public static function push(&$data)
31
    {
32 1
        static::$storage[] = &$data;
33 1
        static::calc();
34 1
    }
35
36 1
    public static function pop()
37
    {
38 1
        if (!empty(static::$storage))
39
        {
40 1
            Arr::pop(static::$storage);
41 1
            static::$index--;
42
        }
43 1
    }
44
45 1
    public function render(): string
46
    {
47 1
        return '<?php \\' . __CLASS__ . '::push(' . $this->data['name']['code'] . ')?>';
48
    }
49
50 1
    public function endDirective(): string
51
    {
52 1
        return '<?php \\' . __CLASS__ . '::pop()?>';
53
    }
54
55
}
56