Passed
Push — master ( 2238ae...4e52d1 )
by Brian
02:41
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
10
class BaseAction implements RenderableTag
11
{
12
    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...
13
    use Expressions;
14
15
    protected \DOMNode $node;
16
    protected Store $store;
17
18 2
    public function __construct(\DOMNode $node, Store $store)
19
    {
20 2
        $this->node = $node;
21 2
        $this->store = $store;
22
    }
23
24 1
    public function handle(): ?string
25
    {
26 1
        $this->shiftCursor();
27
28 1
        $fails = $this->store->get('fails', 0);
29
30 1
        return $fails
31
            ? $this->readAttr('error', 'Something went wrong. Try again:')
32 1
            : $this->readAttr('text');
33
    }
34
35 1
    protected function shiftCursor(): void
36
    {
37 1
        $exp = $this->store->get('_exp');
38
39 1
        $this->store->put('_pre', $exp);
40 1
        $this->store->put('_exp', $this->incExp($exp));
41
    }
42
}
43