Expressions::incExp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 2
crap 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)|', static function ($matches) use ($step) {
15 1
            return $matches[1] - $step;
16 1
        }, $exp);
17
    }
18
19 20
    protected function incExp(?string $exp, int $step = 1): string
20
    {
21 20
        return preg_replace_callback('|(\d+)(?!.*\d)|', static function ($matches) use ($step) {
22 18
            return $matches[1] + $step;
23 20
        }, $exp);
24
    }
25
}
26