Passed
Push — master ( 70b943...71dc1c )
by Brian
02:42
created

BaseAction::handle()   A

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\Store;
8
use Bmatovu\Ussd\Traits\Attributes;
9
use Bmatovu\Ussd\Traits\Expressions;
10
use Bmatovu\Ussd\Traits\Variables;
11
12
class BaseAction implements RenderableTag, AnswerableTag
13
{
14
    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...
15
    use Expressions;
16
    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...
17
18
    protected \DOMNode $node;
19
    protected Store $store;
20
21 2
    public function __construct(\DOMNode $node, Store $store)
22
    {
23 2
        $this->node = $node;
24 2
        $this->store = $store;
25
    }
26
27 1
    public function handle(): ?string
28
    {
29 1
        $this->shiftCursor();
30
31 1
        $fails = $this->store->get('fails', 0);
32
33 1
        return $fails
34
            ? $this->readAttrText('error', 'InternalError')
35 1
            : $this->readAttrText();
36
    }
37
38
    public function process(?string $answer): void
39
    {
40
        // silence is gold...
41
    }
42
43 1
    protected function shiftCursor(): void
44
    {
45 1
        $exp = $this->store->get('_exp');
46
47 1
        $this->store->put('_pre', $exp);
48 1
        $this->store->put('_exp', $this->incExp($exp));
49
    }
50
}
51