From 30cc55f5c9deb87a3f0cd56a67b3f73bc1a9a6ae Mon Sep 17 00:00:00 2001 From: Shu Saura <35106430+shusaura85@users.noreply.github.com> Date: Thu, 14 Dec 2023 13:43:14 +0200 Subject: [PATCH] restore PHP 7.0 compatibility --- README.md | 5 ++- composer.json | 2 +- src/Fancourier/Auth.php | 21 +++++----- src/Fancourier/Client.php | 40 +++++++++---------- src/Fancourier/Fancourier.php | 2 +- src/Fancourier/Objects/Pudo.php | 6 +-- src/Fancourier/Response/GetAwbEvents.php | 2 +- src/Fancourier/Response/GetBankTransfers.php | 2 +- src/Fancourier/Response/GetCities.php | 2 +- src/Fancourier/Response/GetCounties.php | 2 +- src/Fancourier/Response/GetCountries.php | 2 +- .../Response/GetCourierOrderEvents.php | 2 +- src/Fancourier/Response/GetCourierOrders.php | 2 +- src/Fancourier/Response/GetPudo.php | 2 +- src/Fancourier/Response/GetServiceOptions.php | 2 +- src/Fancourier/Response/GetServices.php | 2 +- src/Fancourier/Response/GetShippingSlip.php | 2 +- src/Fancourier/Response/TrackAwb.php | 2 +- src/Fancourier/Response/TrackCourierOrder.php | 2 +- 19 files changed, 51 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 3865a9e..1efa1e6 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,10 @@ All requests have the method `getData()` that returns the unprocessed response o ## Installation ### Requirements -* PHP >= 8.1 +* PHP >= 7.0 -**INFO** It can work with previous versions of PHP (not recommended) if you strip the type and return type declarations from the library +**NOTE** At the moment it's designed to work with PHP 7.0 and newer. +However, the plan is to add type and return type declarations for all functions that will push the requirements to PHP 8.1 at the minimum ### Composer Require the package via composer diff --git a/composer.json b/composer.json index e47e13d..1b5728d 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": ">=8.1", + "php": ">=7.0", "ext-curl": "*", "ext-json": "*" }, diff --git a/src/Fancourier/Auth.php b/src/Fancourier/Auth.php index 0b8682d..777d16a 100644 --- a/src/Fancourier/Auth.php +++ b/src/Fancourier/Auth.php @@ -5,26 +5,25 @@ use Fancourier\Fancourier; use Fancourier\Client; -class Auth -{ - private $clientId; - private $username; - private $password; +class Auth { + private $clientId; + private $username; + private $password; private $btoken = ''; private $btoken_message = ''; protected $gateway = 'login'; - public function __construct($clientId, $username, $password, $token = '') - { - $this->clientId = $clientId; - $this->username = $username; - $this->password = $password; + public function __construct($clientId, $username, $password, $token = '') + { + $this->clientId = $clientId; + $this->username = $username; + $this->password = $password; $this->btoken = $token; // if the token is empty, it will automatically retrieve it when performing a request - } + } public function getClientId() { return $this->clientId; } public function getClientUsername() { return $this->username; } diff --git a/src/Fancourier/Client.php b/src/Fancourier/Client.php index 8e121c6..fe79b6b 100644 --- a/src/Fancourier/Client.php +++ b/src/Fancourier/Client.php @@ -2,17 +2,17 @@ namespace Fancourier; class Client { - private \CurlHandle|false $curl; + private $curl; // \CurlHandle|false - private string $error = ''; - private int $error_no = 0; + private $error = ''; + private $error_no = 0; - private bool $is_put = false; - private bool $is_delete = false; + private $is_put = false; + private $is_delete = false; - private string $useragent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0'; + private $useragent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0'; - private array $headers = []; // custom headers + private $headers = []; // custom headers public function __construct(?string $useragent = null) { @@ -25,7 +25,7 @@ public function __construct(?string $useragent = null) /* * Init curl and set common options. Called by get/post functions */ - private function init(int $con_timeout = 60, int $timeout = 600): void + private function init(int $con_timeout = 60, int $timeout = 600) { $this->curl = curl_init(); // init default data @@ -42,7 +42,7 @@ private function init(int $con_timeout = 60, int $timeout = 600): void $this->set_custom_headers(); } - private function set_custom_headers(): void + private function set_custom_headers() { if (count($this->headers) > 0) { @@ -56,7 +56,7 @@ private function set_custom_headers(): void } } - private function close(): void + private function close() { curl_close($this->curl); // reset put/delete requests @@ -99,7 +99,7 @@ public function get(string $url, int $con_timeout = 60, int $timeout = 600): str Use this static function to prepare a file for posting it using cURL Pass the resulting object of this function inside the $data array of the post function */ - public static function prepare_file(string $file): \CURLFile + public static function prepare_file(string $file) //: \CURLFile { $mime = mime_content_type($file); $info = pathinfo($file); @@ -112,13 +112,13 @@ public static function prepare_file(string $file): \CURLFile Use this static function to prepare a string for posting it using cURL to a file field Pass the resulting object of this function inside the $data array of the post function */ - public static function prepare_file_string(string $data, string $postname, string $mime = 'text/plain'): \CURLStringFile + public static function prepare_file_string(string $data, string $postname, string $mime = 'text/plain') //: \CURLStringFile { return new \CURLStringFile($data, $postname, $mime); } - public function post(string $url, array $data, int $con_timeout = 60, int $timeout = 600): string|false + public function post(string $url, array $data, int $con_timeout = 60, int $timeout = 600) { $this->init($con_timeout, $timeout); @@ -151,7 +151,7 @@ public function post(string $url, array $data, int $con_timeout = 60, int $timeo } // curl doesn't like multilevel arrays in CURLOPT_POSTFIELDS, so we have to manually build the data with http_build_query - public function post_ma(string $url, array $data, int $con_timeout = 60, int $timeout = 600): string|false + public function post_ma(string $url, array $data, int $con_timeout = 60, int $timeout = 600) { $this->init($con_timeout, $timeout); @@ -191,7 +191,7 @@ public function post_ma(string $url, array $data, int $con_timeout = 60, int $ti return false; } - public function post_json(string $url, array $data, int $con_timeout = 60, int $timeout = 600): array|false + public function post_json(string $url, array $data, int $con_timeout = 60, int $timeout = 600) { $this->init($con_timeout, $timeout); @@ -240,7 +240,7 @@ public function post_json(string $url, array $data, int $con_timeout = 60, int $ return false; } - private function set_error(string $error): self + private function set_error(string $error) { $this->error = $error; return $this; @@ -251,7 +251,7 @@ public function get_error(): string return $this->error; } - private function set_error_no(int $errno): self + private function set_error_no(int $errno) { $this->error_no = $errno; return $this; @@ -265,7 +265,7 @@ public function get_error_no(): int /* * Add a custom header to curl */ - public function headers_add($name, $value): self + public function headers_add($name, $value) { $this->headers[ $name ] = $value; return $this; @@ -274,7 +274,7 @@ public function headers_add($name, $value): self /* * Remove a custom header from curl requests */ - public function headers_delete($name): self + public function headers_delete($name) { if (array_key_exists($name, $this->headers)) { @@ -287,7 +287,7 @@ public function headers_delete($name): self * Clear all custom headers from curl */ - public function headers_reset(): self + public function headers_reset() { $this->headers = []; return $this; diff --git a/src/Fancourier/Fancourier.php b/src/Fancourier/Fancourier.php index 3f6ea78..e03e5db 100644 --- a/src/Fancourier/Fancourier.php +++ b/src/Fancourier/Fancourier.php @@ -280,7 +280,7 @@ public function getBankTransfers(GetBankTransfers $request) * @param GetBranches $request * @return \Fancourier\Response\GetBranches */ - public function getBranches($request) + public function getBranches(GetBranches $request) { return $this->send($request); } diff --git a/src/Fancourier/Objects/Pudo.php b/src/Fancourier/Objects/Pudo.php index ff990a1..857ee6f 100644 --- a/src/Fancourier/Objects/Pudo.php +++ b/src/Fancourier/Objects/Pudo.php @@ -74,17 +74,17 @@ public function getAddress(): array return $this->address ?? ''; } - public function getSchedule(): array|string + public function getSchedule() //: array|string { return $this->schedule ?? ''; } - public function getDrawer(): array|string + public function getDrawer() //: array|string { return $this->drawer ?? ''; } - public function getPhones(): array|string + public function getPhones() //: array|string { return $this->phones ?? ''; } diff --git a/src/Fancourier/Response/GetAwbEvents.php b/src/Fancourier/Response/GetAwbEvents.php index b7f7ae6..445a473 100644 --- a/src/Fancourier/Response/GetAwbEvents.php +++ b/src/Fancourier/Response/GetAwbEvents.php @@ -46,7 +46,7 @@ public function getAll(): array return $this->result ?? []; } - public function getEvent($eventId): AwbEvent|false + public function getEvent($eventId) //: AwbEvent|false { $return = false; if (isset($this->result[ $eventId ])) diff --git a/src/Fancourier/Response/GetBankTransfers.php b/src/Fancourier/Response/GetBankTransfers.php index 6f3799e..e94f67d 100644 --- a/src/Fancourier/Response/GetBankTransfers.php +++ b/src/Fancourier/Response/GetBankTransfers.php @@ -55,7 +55,7 @@ public function getAll(): array return $this->result ?? []; } - public function get($position = 0): BankTransfer|false; + public function get($position = 0) //: BankTransfer|false; { return $this->result[$position] ?? false; } diff --git a/src/Fancourier/Response/GetCities.php b/src/Fancourier/Response/GetCities.php index 1cb7d29..d5f1170 100644 --- a/src/Fancourier/Response/GetCities.php +++ b/src/Fancourier/Response/GetCities.php @@ -46,7 +46,7 @@ public function getAll(): array return $this->result ?? []; } - public function getCity($cityname): City|false + public function getCity($cityname) //: City|false { $return = false; foreach ($this->result as $cid=>$cv) diff --git a/src/Fancourier/Response/GetCounties.php b/src/Fancourier/Response/GetCounties.php index 3c2f9e1..be91430 100644 --- a/src/Fancourier/Response/GetCounties.php +++ b/src/Fancourier/Response/GetCounties.php @@ -47,7 +47,7 @@ public function getAll(): array } - public function getCounty($name): County|false + public function getCounty($name) //: County|false { return $this->result[ $name ] ?? false; } diff --git a/src/Fancourier/Response/GetCountries.php b/src/Fancourier/Response/GetCountries.php index 3a5d02d..3dacfd6 100644 --- a/src/Fancourier/Response/GetCountries.php +++ b/src/Fancourier/Response/GetCountries.php @@ -47,7 +47,7 @@ public function getAll(): array } - public function getCountry($name): Country|false + public function getCountry($name) //: Country|false { return $this->result[ $name ] ?? false; } diff --git a/src/Fancourier/Response/GetCourierOrderEvents.php b/src/Fancourier/Response/GetCourierOrderEvents.php index 2034e40..dededb7 100644 --- a/src/Fancourier/Response/GetCourierOrderEvents.php +++ b/src/Fancourier/Response/GetCourierOrderEvents.php @@ -47,7 +47,7 @@ public function getAll(): array } - public function getEvent($courierEventId): CourierOrderEvent|false + public function getEvent($courierEventId) //: CourierOrderEvent|false { return $this->result[ $courierEventId ] ?? false; } diff --git a/src/Fancourier/Response/GetCourierOrders.php b/src/Fancourier/Response/GetCourierOrders.php index c79d696..475fffe 100644 --- a/src/Fancourier/Response/GetCourierOrders.php +++ b/src/Fancourier/Response/GetCourierOrders.php @@ -54,7 +54,7 @@ public function getAll(): array return $this->result ?? []; } - public function get($orderId): CourierOrder|false + public function get($orderId) //: CourierOrder|false { return $this->result[$orderId] ?? false; } diff --git a/src/Fancourier/Response/GetPudo.php b/src/Fancourier/Response/GetPudo.php index 9ee4f8d..0e6f365 100644 --- a/src/Fancourier/Response/GetPudo.php +++ b/src/Fancourier/Response/GetPudo.php @@ -47,7 +47,7 @@ public function getAll(): array return $this->result ?? []; } - public function get($pudoId = null): Pudo|false + public function get($pudoId = null) //: Pudo|false { if (is_null($pudoId)) { diff --git a/src/Fancourier/Response/GetServiceOptions.php b/src/Fancourier/Response/GetServiceOptions.php index 7ae7312..56b1c93 100644 --- a/src/Fancourier/Response/GetServiceOptions.php +++ b/src/Fancourier/Response/GetServiceOptions.php @@ -51,7 +51,7 @@ public function hasOption($code): bool return isset($this->result[ $code ]); } - public function getOption($code): ServiceOption|false + public function getOption($code) //: ServiceOption|false { return $this->result[ $code ] ?? false; } diff --git a/src/Fancourier/Response/GetServices.php b/src/Fancourier/Response/GetServices.php index 673ce64..ff6bcc9 100644 --- a/src/Fancourier/Response/GetServices.php +++ b/src/Fancourier/Response/GetServices.php @@ -52,7 +52,7 @@ public function hasService($name): bool return isset($this->result[ $name ]); } - public function getService($name): Service|false + public function getService($name) //: Service|false { return $this->result[ $name ] ?? false; } diff --git a/src/Fancourier/Response/GetShippingSlip.php b/src/Fancourier/Response/GetShippingSlip.php index 1feb870..e6b7c5c 100644 --- a/src/Fancourier/Response/GetShippingSlip.php +++ b/src/Fancourier/Response/GetShippingSlip.php @@ -55,7 +55,7 @@ public function getAll(): array return $this->result ?? []; } - public function get($position): ShippingSlip|false + public function get($position) //: ShippingSlip|false { return $this->result[$position] ?? false; } diff --git a/src/Fancourier/Response/TrackAwb.php b/src/Fancourier/Response/TrackAwb.php index e548799..83a5dc6 100644 --- a/src/Fancourier/Response/TrackAwb.php +++ b/src/Fancourier/Response/TrackAwb.php @@ -47,7 +47,7 @@ public function getAll(): array } - public function getAwb($awnNo): AwbTracker|false + public function getAwb($awnNo) //: AwbTracker|false { return $this->result[ $awbNo ] ?? false; } diff --git a/src/Fancourier/Response/TrackCourierOrder.php b/src/Fancourier/Response/TrackCourierOrder.php index ba83af6..f925fed 100644 --- a/src/Fancourier/Response/TrackCourierOrder.php +++ b/src/Fancourier/Response/TrackCourierOrder.php @@ -47,7 +47,7 @@ public function getAll(): array } - public function getOrder($orderId): CourierOrderTracker|false + public function getOrder($orderId) //: CourierOrderTracker|false { return $this->result[ $orderId ] ?? false; }