BaseAction::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 6
cp 0.8333
rs 10
cc 2
nc 2
nop 0
crap 2.0185
1
<?php
2
3
namespace Bmatovu\Ussd\Actions;
4
5
use Bmatovu\Ussd\Contracts\AnswerableTag;
6
use Bmatovu\Ussd\Contracts\RenderableTag;
7
use Bmatovu\Ussd\Exceptions\FlowBreakException;
8
use Bmatovu\Ussd\Store;
9
use Bmatovu\Ussd\Traits\Attributes;
10
use Bmatovu\Ussd\Traits\Expressions;
11
use Bmatovu\Ussd\Traits\Variables;
12
13
class BaseAction implements RenderableTag, AnswerableTag
14
{
15
    use Attributes;
0 ignored issues
show
introduced by
The trait Bmatovu\Ussd\Traits\Attributes requires some properties which are not provided by Bmatovu\Ussd\Actions\BaseAction: $attributes, $nodeValue
Loading history...
16
    use Expressions;
17
    use Variables;
0 ignored issues
show
Bug introduced by
The trait Bmatovu\Ussd\Traits\Variables requires the property $childNodes which is not provided by Bmatovu\Ussd\Actions\BaseAction.
Loading history...
18
19
    protected \DOMNode $node;
20
    protected Store $store;
21
22 2
    public function __construct(\DOMNode $node, Store $store)
23
    {
24 2
        $this->node = $node;
25 2
        $this->store = $store;
26
    }
27
28 1
    public function handle(): ?string
29
    {
30 1
        $this->shiftCursor();
31
32 1
        $fails = $this->store->get('fails', 0);
33
34 1
        return $fails
35
            ? $this->readAttrText('error', 'InternalError')
36 1
            : $this->readAttrText();
37
    }
38
39
    public function process(?string $answer): void
40
    {
41
        throw new FlowBreakException('Override this func...');
42
    }
43
44 1
    protected function shiftCursor(): void
45
    {
46 1
        $exp = $this->store->get('_exp');
47
48 1
        $this->store->put('_pre', $exp);
49 1
        $this->store->put('_exp', $this->incExp($exp));
50
    }
51
}
52