Directive::randVariable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Bavix\Flow;
4
5
use Bavix\Exceptions\Invalid;
6
use Bavix\Helpers\Str;
7
8
abstract class Directive
9
{
10
11
    /**
12
     * @var Flow
13
     */
14
    protected $flow;
15
16
    /**
17
     * @var array
18
     */
19
    protected $data;
20
21
    /**
22
     * @var array
23
     */
24
    protected $operator;
25
26
    /**
27
     * Directive constructor.
28
     *
29
     * @param Flow  $flow
30
     * @param array $data
31
     * @param array $operator
32
     */
33 13
    public function __construct(Flow $flow, array $data, array $operator)
34
    {
35 13
        $this->flow     = $flow;
36 13
        $this->data     = $data;
37 13
        $this->operator = $operator;
38 13
    }
39
40
    /**
41
     * @return string
42
     */
43 6
    protected function randVariable(): string
44
    {
45 6
        return '$_' . Str::random(16);
46
    }
47
48
    /**
49
     * @codeCoverageIgnore
50
     *
51
     * @return string
52
     */
53
    public function endDirective(): string
54
    {
55
        throw new Invalid('Undefined directive `' . $this->operator['fragment']);
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function __toString()
62
    {
63
        return $this->render();
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    abstract public function render(): string;
70
71
}
72