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

Expressions   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 4
b 0
f 0
dl 0
loc 19
ccs 9
cts 10
cp 0.9
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A decExp() 0 9 2
A incExp() 0 5 1
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