src/Package.php
/**
     * Determines the package's shipping details based on its tracking code.
     *
     * @return Argo\Package
     */
Determines the package's shipping details based on its tracking code.
@return Argo\Package
Determines the package ' s shipping details based on its tracking code . @return Argo \ Package
private function deduceTrackingCode(): Package
    {
        $tracking_code = $this->tracking_code;
        $carrier_code  = null;
        $provider_code = null;
        if (preg_match('/^[0-9]{2}[0-9]{4}[0-9]{4}$/', $tracking_code, $matches)) {
            $carrier_code = Carrier::CODE_DHL;
        } elseif (preg_match('/^[1-9]{4}[0-9]{4}[0-9]{4}$/', $tracking_code, $matches)) {
            $carrier_code = Carrier::CODE_FEDEX;
        } elseif (preg_match('/^1Z[A-Z0-9]{3}[A-Z0-9]{3}[0-9]{2}[0-9]{4}[0-9]{4}$/i', $tracking_code)) {
            $carrier_code = Carrier::CODE_UPS;
        } elseif (preg_match('/^[0-9]{4}[0-9]{4}[0-9]{4}[0-9]{4}[0-9]{4}[0-9]{2}$/', $tracking_code)) {
            $carrier_code = Carrier::CODE_USPS;
        } elseif (preg_match('/^LX[0-9]{8}$/', $tracking_code)) {
            $carrier_code = Carrier::CODE_LASER_SHIP;
        } elseif (preg_match('/^C\d{14}$/', $tracking_code)) {
            $carrier_code = Carrier::CODE_ONTRAC;
        } elseif (preg_match(
            '/^420[0-9]{5}([0-9]{4}[0-9]{4}[0-9]{4}[0-9]{4}[0-9]{4}[0-9]{2})$/',
            $tracking_code,
            $matches
        )) {
            $this->tracking_code = $matches[1];
            $carrier_code = Carrier::CODE_USPS;
            $provider_code = Provider::CODE_ENDICIA;
        }
        if (!empty($carrier_code)) {
            $this->carrier = new Carrier($carrier_code);
            $this->provider = new Provider($provider_code ?: $carrier_code);
        }
        return $this;
    }
private function deduceTrackingCode ( ) : Package { $ tracking_code = $ this -> tracking_code ; $ carrier_code = null ; $ provider_code = null ; if ( preg_match ( '/^[0-9]{2}[0-9]{4}[0-9]{4}$/' , $ tracking_code , $ matches ) ) { $ carrier_code = Carrier :: CODE_DHL ; } elseif ( preg_match ( '/^[1-9]{4}[0-9]{4}[0-9]{4}$/' , $ tracking_code , $ matches ) ) { $ carrier_code = Carrier :: CODE_FEDEX ; } elseif ( preg_match ( '/^1Z[A-Z0-9]{3}[A-Z0-9]{3}[0-9]{2}[0-9]{4}[0-9]{4}$/i' , $ tracking_code ) ) { $ carrier_code = Carrier :: CODE_UPS ; } elseif ( preg_match ( '/^[0-9]{4}[0-9]{4}[0-9]{4}[0-9]{4}[0-9]{4}[0-9]{2}$/' , $ tracking_code ) ) { $ carrier_code = Carrier :: CODE_USPS ; } elseif ( preg_match ( '/^LX[0-9]{8}$/' , $ tracking_code ) ) { $ carrier_code = Carrier :: CODE_LASER_SHIP ; } elseif ( preg_match ( '/^C\d{14}$/' , $ tracking_code ) ) { $ carrier_code = Carrier :: CODE_ONTRAC ; } elseif ( preg_match ( '/^420[0-9]{5}([0-9]{4}[0-9]{4}[0-9]{4}[0-9]{4}[0-9]{4}[0-9]{2})$/' , $ tracking_code , $ matches ) ) { $ this -> tracking_code = $ matches [ 1 ] ; $ carrier_code = Carrier :: CODE_USPS ; $ provider_code = Provider :: CODE_ENDICIA ; } if ( ! empty ( $ carrier_code ) ) { $ this -> carrier = new Carrier ( $ carrier_code ) ; $ this -> provider = new Provider ( $ provider_code ? : $ carrier_code ) ; } return $ this ; }
Determines the package's shipping details based on its tracking code.
Determines the package ' s shipping details based on its tracking code .