<commit_before><?php
//Lookup msisdn
//preveri številko - get
//E.164 protokol
namespace App;

class Lookup
{

    public function __construct()
    {
        include "App/DB.php";
    }
    
    private $modeID = 0;

    public static function msisdn($number)
    {
        $self = new Lookup;
        //clean up the number
        $number = $self->cleanNumber($number);
        if ($number != "") {
            //connect to base via PDO
            $dataB = new \App\DB\Database();

            //first need to check what country is it, so first 3 numbers
            
            $countyCode = $self->checkCountry($number, $dataB);
            $result = $countyCode;
            if (!empty($countyCode)) {
                //check what network -> country code
                $returned = $self->checkNetwork($countyCode['country_code'], substr($number, $self->modeID, 3), $dataB);
                if (empty($returned)) {
                    $result['error'] = "Unknown NDC";
                } else {
                    $result = $returned;
                    $result['numberDetail'] = $result['country_code'] ." ". $result['ndc'] ." ". substr($number, $self->modeID);
                }
            } else {
                $result['error'] = "Unknown Country";
            }
            $result['Subscribe'] = substr($number, $self->modeID);
        } else {           
            $result['error'] = "Cant be null";
        }
        $result['number'] = $number;
        //print_r($result);
        return $result;
    }
    public function cleanNumber($number)
    {
        $number = preg_replace('/\D/', '', $number); //allow only numbers
        $number = preg_replace('/(^00)/', '', $number); //remove double zero

        return $number;
    }

    public function checkCountry($number, $dataB)
    {
        for ($i=1; $i <= 3; $i++) {
            //get first three characters
            $countyCode = substr($number, 0, $i);
            //chech if in base
            $return = $dataB->getRow("SELECT country, country_code, ISO FROM info WHERE country_code = $countyCode");
            if ($return) {
                $this->modeID = $i;
                break;
            }
        }
        return $return;
    }

    public function checkNetwork($countyCode, $ndc, $dataB)
    {
        $result = array();
        //chech if in base
        for ($i=1; $i <= 3; $i++) {
            //get first three characters
            $ndcsub = substr($ndc, 0, $i);
            //chech if in base
            $return = $dataB->getRow("SELECT * FROM info WHERE country_code = $countyCode AND ndc = $ndcsub");
            if ($return) {
                $result = $return;
                $this->modeID += $i;
            }
            //we need only the last one (max 3, min 1)
            //if found at 1 still can overwrite after 3
            //example: 1-800-999-9999 US will found at 80 but its unknown so go to 800 T-Mobile
        }
        return $result;
    }
}<commit_msg>0.3.3 version<commit_after><?php
//Lookup msisdn
//preveri številko - get
//E.164 protokol
namespace App;

use Exception;

class Lookup
{

    public function __construct()
    {
        include "App/DB.php";
    }
    
    private $modeID = 0;

    public static function msisdn($number)
    {
        $self = new Lookup;
        //clean up the number
        $number = $self->cleanNumber($number);

        if ($number != "") {
            //connect to base via PDO
            $dataB = new \App\DB\Database();

            //first need to check what country is it, so first 3 numbers
            $whereId = "country_code";
            $what = "country_code, country, ISO";
            $result = $self->checkQuery($number, $whereId, $dataB, $what);

            if (!empty($result)) {
                //check what network -> country code
                $where = "AND country_code  = " . $result['country_code'];
                $ndc = substr($number, $self->modeID, 3);
                $whereId = "ndc";
                $returned = $self->checkQuery($ndc, "ndc", $dataB, "*", $where);

                if (empty($returned)) {
                    $result['error'] = "Unknown NDC";
                } else {
                    $result = $returned;
                    $result['numberDetail'] = $result['country_code'] ." ". $result['ndc'] ." ". substr($number, $self->modeID);
                }
            } else {
                $result['error'] = "Unknown Country";
            }
            $result['Subscribe'] = substr($number, $self->modeID);
        } else {           
            $result['error'] = "This is not a MSISDN?";
        }
        $result['number'] = $number;
        return $result;
    }

    public function checkQuery($ndc, $valueWhere, $dataB, $what = "*", $where = "") {
        $result = array();
        //chech if in base
        for ($i=1; $i <= 3; $i++) {
            //get first three characters
            $ndcsub = substr($ndc, 0, $i);
            //chech if in base
            $query = "SELECT $what FROM info WHERE $valueWhere = $ndcsub $where";
            $return = $dataB->getRow($query);
            if ($return) {
                $result = $return;
                $this->modeID += $i;
            }
            //we need only the last one (max 3, min 1)
            //if found at 1 still can overwrite after 3
            //example: 1-800-999-9999 US will found at 80 but its unknown so go to 800 T-Mobile
        }
        return $result;
    }

    public function cleanNumber($number) {
        $number = preg_replace('/\D/', '', $number); //allow only numbers
        $number = preg_replace('/(^00)/', '', $number); //remove double zero
        if (strlen($number) < 6) { //11 or 15 character is MSISDN!? So i could put that higher :D
            return false;
        }
        return $number;
    }
}
{'fraction_non_alphanumeric': 0.14442350522528696, 'fraction_numerical': 0.012506424533150592, 'mean_word_length': 1.5763459841129743, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2678352', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1651, 'n_words': 478}