inspection fixes

This commit is contained in:
Dennis Eichhorn 2023-09-21 03:11:01 +00:00
parent d8fd9b74d2
commit 3925cb6be7
6 changed files with 55 additions and 15 deletions

View File

@ -104,7 +104,7 @@ class GeneticOptimization
) : array
{
$populationSize = \count($population);
$parameterCount = \count(\reset($population));
$parameterCount = $populationSize === 0 ? 0 : \count(\reset($population));
// Genetic Algorithm Loop
for ($generation = 0; $generation < $generations; ++$generation) {

View File

@ -137,7 +137,7 @@ final class CreditSafe implements CreditRatingInterface
$response = Rest::request($request);
return $response->get('companies') ?? ($response->get('matchedCompanies') ?? []);
return $response->getDataArray('companies') ?? ($response->getDataArray('matchedCompanies') ?? []);
}
/**
@ -158,7 +158,7 @@ final class CreditSafe implements CreditRatingInterface
$response = Rest::request($request);
return $response->get('report') ?? [];
return $response->getDataArray('report') ?? [];
}
/**
@ -233,7 +233,7 @@ final class CreditSafe implements CreditRatingInterface
$response = Rest::request($request);
return $response->get('orders') ?? [];
return $response->getDataArray('orders') ?? [];
}
/**

View File

@ -37,7 +37,7 @@ final class JWT
*
* @param string $secret Secret (at least 256 bit)
* @param array{alg:string, typ:string} $header Header
* @param array{sub:string, ?uid:string, ?name:string, iat:string} $payload Payload
* @param array{sub:string, uid?:string, name?:string, iat:string} $payload Payload
*
* @return string hmac(Header64 . Payload64, secret)
*
@ -45,8 +45,15 @@ final class JWT
*/
private static function createSignature(string $secret, array $header, array $payload) : string
{
$header64 = Base64Url::encode(\json_encode($header));
$payload64 = Base64Url::encode(\json_encode($payload));
$headerJson = \json_encode($header);
$payloadJson = \json_encode($payload);
if (!\is_string($headerJson) || !\is_string($payloadJson)) {
return '';
}
$header64 = Base64Url::encode($headerJson);
$payload64 = Base64Url::encode($payloadJson);
$algorithm = '';
$algorithm = 'sha256';
@ -59,7 +66,7 @@ final class JWT
*
* @param string $secret Secret (at least 256 bit)
* @param array{alg:string, typ:string} $header Header
* @param array{sub:string, ?uid:string, ?name:string, iat:string} $payload Payload
* @param array{sub:string, uid?:string, name?:string, iat:string} $payload Payload
*
* @return string Header64 . Payload64 . hmac(Header64 . Payload64, secret)
*
@ -67,8 +74,16 @@ final class JWT
*/
public static function createJWT(string $secret, array $header, array $payload) : string
{
$header64 = Base64Url::encode(\json_encode($header));
$payload64 = Base64Url::encode(\json_encode($payload));
$headerJson = \json_encode($header);
$payloadJson = \json_encode($payload);
if (!\is_string($headerJson) || !\is_string($payloadJson)) {
return '';
}
$header64 = Base64Url::encode($headerJson);
$payload64 = Base64Url::encode($payloadJson);
$signature = self::createSignature($secret, $header, $payload);
return $header64 . $payload64 . Base64Url::encode($signature);
@ -87,7 +102,7 @@ final class JWT
{
$explode = \explode('.', $jwt);
if ($explode !== 3) {
if (\count($explode) !== 3) {
return [];
}
@ -107,7 +122,7 @@ final class JWT
{
$explode = \explode('.', $jwt);
if ($explode !== 3) {
if (\count($explode) !== 3) {
return [];
}
@ -128,7 +143,7 @@ final class JWT
{
$explode = \explode('.', $jwt);
if ($explode !== 3) {
if (\count($explode) !== 3) {
return false;
}

View File

@ -102,7 +102,7 @@ class ImpressionStat
/**
* Additional custom meta data to be stored
*
* @var string
* @var array
* @since 1.0.0
*/
public array $meta = [];

View File

@ -100,6 +100,26 @@ abstract class ResponseAbstract implements \JsonSerializable, MessageInterface
return (string) $this->data[$key];
}
/**
* Get data.
*
* @param string $key Data key
*
* @return ?array
*
* @since 1.0.0
*/
public function getDataArray(string $key) : ?array
{
$key = \mb_strtolower($key);
if (($this->data[$key] ?? '') === '' || !\is_array($this->data[$key])) {
return null;
}
return $this->data[$key];
}
/**
* Get data.
*

View File

@ -121,7 +121,12 @@ final class SystemUtils
return -1;
}
$cpuUsage = $loadavg[0] * 100 / \exec('nproc');
$nproc = (int) \exec('nproc');
if ($nproc === 0) {
return 0;
}
$cpuUsage = $loadavg[0] * 100 / $nproc;
}
return (int) $cpuUsage;