Phone::toIntlFormat()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.6111
cc 5
nc 3
nop 3
crap 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