FormatMsisdnAction   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 2
b 0
f 0
dl 0
loc 20
ccs 0
cts 10
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 18 3
1
<?php
2
3
namespace Bmatovu\Ussd\Actions;
4
5
/**
6
 * Usage:
7
 *
8
 * ```xml
9
 * <action name="format_msisdn" msisdn="0743876123" country_code="256" />
10
 * <response text="{{fmt_msisdn}}" /><!-- 256743876123 -->
11
 * ```
12
 */
13
class FormatMsisdnAction extends BaseAction
14
{
15
    public function process(?string $answer): void
16
    {
17
        $msisdn = $this->readAttr('msisdn', $this->store->get('msisdn'));
18
19
        if (!$msisdn) {
20
            return;
21
        }
22
23
        $msisdn = preg_replace('/[^\d]/', '', $msisdn);
24
25
        $country_code = $this->readAttr('country_code');
26
        if ($country_code) {
27
            $msisdn = preg_replace('/^0/', $country_code, $msisdn);
28
        }
29
30
        $prefix = $this->readAttr('prefix', 'fmt');
31
32
        $this->store->put("{$prefix}_msisdn", $msisdn);
33
    }
34
}
35