Skip to content

Commit

Permalink
Min php version updated to 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fustundag committed Mar 9, 2022
1 parent 14c67c8 commit 510a7eb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 39 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"teknasyon"
],
"type": "library",
"minimum-stability": "dev",
"minimum-stability": "stable",
"license": "MIT",
"authors": [
{
Expand All @@ -18,9 +18,11 @@
}
],
"require": {
"php": ">=8.0",
"ext-json": "*",
"ext-redis": "*",
"guzzlehttp/guzzle": "6.*"
"guzzlehttp/guzzle": "7.4.*",
"psr/log": "3.0.*"
},
"autoload": {
"psr-0": {
Expand Down
31 changes: 13 additions & 18 deletions src/Teknasyon/HuaweiMobileService/HuaweiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Teknasyon\HuaweiMobileService;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Monolog\Logger;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Teknasyon\HuaweiMobileService\InAppPurchase\Exceptions\HuaweiException;

class HuaweiClient
Expand Down Expand Up @@ -56,12 +57,12 @@ public function __construct($config, $redis = null, $logger = null)

/**
* @param Request $request
* @param string $expectedClass
* @param null|string $expectedClass
*
* @return ResponseInterface|expectedClass
* @throws HuaweiException
* @return ResponseInterface|mixed
* @throws HuaweiException|GuzzleException
*/
public function execute(Request $request, $expectedClass = "")
public function execute(Request $request, $expectedClass = null)
{
$request = $this->authorize($request);

Expand Down Expand Up @@ -97,7 +98,7 @@ public function execute(Request $request, $expectedClass = "")
* @param RequestInterface $request The http response to be decoded.
* @param null $expectedClass
*
* @return ResponseInterface|expectedClass
* @return ResponseInterface|mixed
* @throws HuaweiException
*/
private function decodeHttpResponse(
Expand Down Expand Up @@ -129,7 +130,7 @@ private function decodeHttpResponse(
try {
return new $expectedClass($json);
} catch (\Exception $e) {
self::log(' Huawei Client Error : Expected Class not found', Logger::WARNING);
self::log(' Huawei Client Error : Expected Class not found', LogLevel::WARNING);
}
}

Expand All @@ -144,11 +145,8 @@ private static function determineExpectedClass($expectedClass, RequestInterface
}

// if we don't have a request, we just use what's passed in
if (null === $request) {
return $expectedClass;
}

return $expectedClass;

}

private function authorize(Request $request)
Expand Down Expand Up @@ -208,7 +206,6 @@ private function getAccessToken()
}
sleep(1);
} while (1);
return null;
}

private function requestAccessTokenFromHuawei()
Expand All @@ -232,14 +229,14 @@ private function requestAccessTokenFromHuawei()
if ($responseStatus == 200 && isset($result['access_token']) && $result['access_token'] != '') {
$this->log(
'Huawei Client Error, Request: ' . json_encode($requestParams) . ', Response: ' .
$responseBody, Logger::DEBUG
$responseBody, LogLevel::DEBUG
);
return [$result['access_token'], $result['expires_in']];
} else {
$this->log(
'Huawei Client Error, Resfresh Token Failed! HttpStatusCode: ' . $responseStatus .
', Request: ' . json_encode($requestParams) . ', Response: ' . $responseBody,
Logger::ERROR
LogLevel::ERROR
);
}

Expand Down Expand Up @@ -283,15 +280,13 @@ private function buildAuthorization($accessToken)
* @param int $level
* @param null $context
*/
public function log($msg, $level = Logger::INFO, $context = null)
public function log($msg, $level = LogLevel::INFO, $context = null)
{
if(!is_array($context)){
$context = array();
}

if ($this->logger) {
$this->logger->log($level, $msg, $context);
}
$this->logger?->log($level, $msg, $context);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,19 @@ public function offsetGet($offset)
public function offsetSet($offset, $value)
{
if (!is_numeric($offset)) {
return parent::offsetSet($offset, $value);
parent::offsetSet($offset, $value);
} else {
$this->{$this->collection_key}[$offset] = $value;
}
$this->{$this->collection_key}[$offset] = $value;
}

public function offsetUnset($offset)
{
if (!is_numeric($offset)) {
return parent::offsetUnset($offset);
parent::offsetUnset($offset);
} else {
unset($this->{$this->collection_key}[$offset]);
}
unset($this->{$this->collection_key}[$offset]);
}

private function coerceType($offset)
Expand Down
10 changes: 3 additions & 7 deletions src/Teknasyon/HuaweiMobileService/InAppPurchase/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __get($key)
}

if ($this->isAssociativeArray($val)) {
if ($keyDataType && 'map' == $keyDataType) {
if ('map' == $keyDataType) {
foreach ($val as $arrayKey => $arrayItem) {
$this->modelData[$key][$arrayKey]
= new $keyType($arrayItem);
Expand All @@ -78,7 +78,7 @@ public function __get($key)
$this->processed[$key] = true;
}

return isset($this->modelData[$key]) ? $this->modelData[$key] : null;
return $this->modelData[$key] ?? null;
}

/**
Expand Down Expand Up @@ -255,11 +255,7 @@ public function offsetExists($offset)

public function offsetGet($offset)
{
return isset($this->$offset)
?
$this->$offset
:
$this->__get($offset);
return $this->$offset ?? $this->__get($offset);
}

public function offsetSet($offset, $value)
Expand Down
16 changes: 8 additions & 8 deletions src/Teknasyon/HuaweiMobileService/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Teknasyon\HuaweiMobileService;

use GuzzleHttp\Psr7\Request;
use Monolog\Logger;
use Psr\Log\LogLevel;
use Psr\Http\Message\ResponseInterface;
use Teknasyon\HuaweiMobileService\HuaweiClient as Client;
use Teknasyon\HuaweiMobileService\InAppPurchase\Exceptions\HuaweiException;
Expand Down Expand Up @@ -50,15 +50,15 @@ public function __construct($service, $resourceName, $resource)
*
* @param $expectedClass - optional, the expected class name
*
* @return ResponseInterface|expectedClass
* @return ResponseInterface|mixed
* @throws HuaweiException
*/
public function call($name, $arguments, $expectedClass = null)
{
if (!isset($this->methods[$name])) {
$this->client->log(
'Service method unknown',
Logger::ERROR,
LogLevel::ERROR,
array(
'service' => $this->serviceName,
'resource' => $this->resourceName,
Expand Down Expand Up @@ -111,7 +111,7 @@ public function call($name, $arguments, $expectedClass = null)
if ($key != 'postBody' && !isset($method['parameters'][$key])) {
$this->client->log(
'Service parameter unknown',
Logger::ERROR,
LogLevel::ERROR,
array(
'service' => $this->serviceName,
'resource' => $this->resourceName,
Expand All @@ -127,7 +127,7 @@ public function call($name, $arguments, $expectedClass = null)
if (isset($paramSpec['required']) && $paramSpec['required'] && !isset($parameters[$paramName])) {
$this->client->log(
'Service parameter missing',
Logger::ERROR,
LogLevel::ERROR,
array(
'service' => $this->serviceName,
'resource' => $this->resourceName,
Expand All @@ -150,7 +150,7 @@ public function call($name, $arguments, $expectedClass = null)

$this->client->log(
'Service Call',
Logger::INFO,
LogLevel::INFO,
array(
'service' => $this->serviceName,
'resource' => $this->resourceName,
Expand Down Expand Up @@ -200,15 +200,15 @@ protected function convertToArrayAndStripNulls($o)
private function createRequestUri($restPath, $params)
{
// Override the default servicePath address if the $restPath use a /
if ('/' == substr($restPath, 0, 1)) {
if (str_starts_with($restPath, '/')) {
$requestUrl = substr($restPath, 1);
} else {
$requestUrl = $restPath;
}

// code for leading slash
if ($this->rootUrl) {
if ('/' !== substr($this->rootUrl, -1) && '/' !== substr($requestUrl, 0, 1)) {
if (!str_ends_with($this->rootUrl, '/') && !str_starts_with($requestUrl, '/')) {
$requestUrl = '/' . $requestUrl;
}
$requestUrl = $this->rootUrl . $requestUrl;
Expand Down

0 comments on commit 510a7eb

Please sign in to comment.