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

BaseAction   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 16
c 2
b 0
f 0
dl 0
loc 37
ccs 12
cts 15
cp 0.8
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 9 2
A process() 0 2 1
A shiftCursor() 0 6 1
A __construct() 0 4 1
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