OperatorIndonesia::check()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Deogw\OperatorIndonesia;
4
5
class OperatorIndonesia
6
{
7
8
    /**
9
     * @var array prefix operator
10
     */
11
    protected static $prefix = array(
12
        'Telkomsel' => ['0811', '0812', '0813', '0821', '0822', '0823', '0851', '0852', '0853'],
13
        'XL' => ['0817', '0818', '0819', '0859', '0877', '0878', '0879'],
14
        'Axis' => ['0831', '0832', '0833', '0837', '0838'],
15
        'Indosat' => ['0814', '0815', '0815', '0816', '0855', '0856', '0857', '0858'],
16
        'Three' => ['0894', '0895', '0896', '0897', '0898', '0899'],
17
        'Smartfren' => ['0881', '0882', '0883', '0884', '0885', '0886', '0887', '0888', '0888'],
18
    );
19
20
21
    /**
22
     * Check Operator/Provider berdasarkan prefix dari 4 angka pertama.
23
     * @param  string $phoneNumber
24
     * @return string Operator
25
     */
26
    public static function check($phoneNumber)
27
    {
28
        $operator = 'Unknown';
29
30
        $normalize = preg_replace('/^\+?62/', '0', $phoneNumber);
31
32
        $prefixFromNumber = substr($normalize, 0, 4);
33
34
        foreach (self::$prefix as $key => $provider) {
35
            if (in_array($prefixFromNumber, $provider)) {
36
                $operator = $key;
37
                break;
38
            }
39
        }
40
41
        return  $operator;
42
    }
43
}
44