OperatorIndonesia   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 39
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 17 3
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