Phone   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 7
c 1
b 0
f 0
dl 0
loc 24
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A toIntlFormat() 0 13 5
1
<?php
2
3
namespace Bmatovu\Beyonic\Support;
4
5
class Phone
6
{
7
    /**
8
     * Format msisdn to international format.
9
     *
10
     * @param string $msisdn
11
     * @param null|string $countryCode
12
     * @param null|string $prefix
13
     *
14
     * @return string
15
     */
16 1
    public static function toIntlFormat($msisdn, $countryCode = '256', $prefix = '+')
17
    {
18 1
        $msisdn = preg_replace("/[^{$prefix}0-9]/", '', $msisdn);
19
20 1
        if ($prefix && 0 === strpos($msisdn, $prefix)) {
21 1
            return $msisdn;
22
        }
23
24 1
        if ($countryCode && 0 === strpos($msisdn, '0')) {
25 1
            $msisdn = preg_replace('/^0/', $countryCode, $msisdn, 1);
26
        }
27
28 1
        return "{$prefix}{$msisdn}";
29
    }
30
}
31