Skip to content

Commit

Permalink
restore PHP 7.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
shusaura85 committed Dec 14, 2023
1 parent e9cd162 commit 30cc55f
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 51 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"php": ">=7.0",
"ext-curl": "*",
"ext-json": "*"
},
Expand Down
21 changes: 10 additions & 11 deletions src/Fancourier/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
40 changes: 20 additions & 20 deletions src/Fancourier/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
Expand All @@ -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)
{
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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))
{
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Fancourier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Fancourier/Objects/Pudo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Response/GetAwbEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]))
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Response/GetBankTransfers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Response/GetCities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Response/GetCounties.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Response/GetCountries.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Response/GetCourierOrderEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Response/GetCourierOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Response/GetPudo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Response/GetServiceOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Response/GetServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Response/GetShippingSlip.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Response/TrackAwb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fancourier/Response/TrackCourierOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 30cc55f

Please sign in to comment.