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