Passed
Push — master ( 78d0af...d10895 )
by Brian
02:44
created

Expressions::decExp()   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 3
Bugs 0 Features 0
Metric Value
eloc 5
c 3
b 0
f 0
dl 0
loc 9
ccs 5
cts 6
cp 0.8333
rs 10
cc 2
nc 2
nop 2
crap 2.0185
1
<?php
2
3
namespace Bmatovu\Ussd\Traits;
4
5
trait Expressions
6
{
7
    // Todo - handle decrement below position 1 edge case
8 1
    protected function decExp(?string $exp, int $step = 1): ?string
9
    {
10 1
        if (!$exp) {
11
            return $exp;
12
        }
13
14 1
        return preg_replace_callback('|(\\d+)(?!.*\\d)|', function ($matches) use ($step) {
15 1
            return $matches[1] - $step;
16 1
        }, $exp);
17
    }
18
19 19
    protected function incExp(string $exp, int $step = 1): string
20
    {
21 19
        return preg_replace_callback('|(\\d+)(?!.*\\d)|', function ($matches) use ($step) {
22 18
            return $matches[1] + $step;
23 19
        }, $exp);
24
    }
25
}
26