From 93a972eb55f4ba076cb530f9b7dc46d15e966a5e Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 6 Jun 2019 21:43:45 +0200 Subject: [PATCH] static analysis fixes --- DataStorage/Database/DataMapperAbstract.php | 11 ++--------- Math/Number/Prime.php | 6 +++++- Message/Http/Rest.php | 5 +++-- Module/ModuleManager.php | 2 +- Validation/Finance/CreditCard.php | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index f13c1940b..dd3f735a2 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -83,16 +83,9 @@ class DataMapperAbstract implements DataMapperInterface protected static $columns = []; /** - * Relations. - * - * Relation is defined in a relation table - * - * @var string[] - * @since 1.0.0 - */ /** * Has many relation. * - * @var array> + * @var array * @since 1.0.0 */ protected static $hasMany = []; @@ -102,7 +95,7 @@ class DataMapperAbstract implements DataMapperInterface * * Relation is defined in current mapper * - * @var string[] + * @var array * @since 1.0.0 */ protected static $ownsOne = []; diff --git a/Math/Number/Prime.php b/Math/Number/Prime.php index 1fb4140c8..214723342 100644 --- a/Math/Number/Prime.php +++ b/Math/Number/Prime.php @@ -62,7 +62,7 @@ final class Prime */ public static function mersenne(int $p) : int { - return 2 ** $p - 1; + return (int) (2 ** $p) - 1; } /** @@ -135,6 +135,10 @@ final class Prime $range = \range(2, $n); $primes = \array_combine($range, $range); + if ($primes === false) { + return []; + } + while ($number * $number < $n) { for ($i = $number; $i <= $n; $i += $number) { if ($i == $number) { diff --git a/Message/Http/Rest.php b/Message/Http/Rest.php index 2a798ae41..090c7b333 100644 --- a/Message/Http/Rest.php +++ b/Message/Http/Rest.php @@ -30,7 +30,7 @@ final class Rest * * @param Request $request Request * - * @return Request Returns the request result + * @return Response Returns the request result * * @throws \Exception this exception is thrown if an internal curl_init error occurs * @@ -104,10 +104,11 @@ final class Rest \curl_setopt($curl, \CURLOPT_RETURNTRANSFER, 1); $result = \curl_exec($curl); + $len = \strlen($cHeaderString); \curl_close($curl); - $response->set('', \substr($result, \strlen($cHeaderString))); + $response->set('', \substr(\is_bool($result) ? '' : $result, $len === false ? 0 : $len)); return $response; } diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index 54c3671bb..5c82696bd 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -48,7 +48,7 @@ final class ModuleManager * * This is important to inform other moduels what kind of information they can receive from other modules. * - * @var \phpOMS\Module\ModuleAbstract[] + * @var array> * @since 1.0.0 */ private $providing = []; diff --git a/Validation/Finance/CreditCard.php b/Validation/Finance/CreditCard.php index bb5d2a2cb..b22be418c 100644 --- a/Validation/Finance/CreditCard.php +++ b/Validation/Finance/CreditCard.php @@ -45,7 +45,7 @@ final class CreditCard extends ValidatorAbstract // Loop through each digit and do the maths $total = 0; for ($i = 0; $i < $numberLength; ++$i) { - $digit = $value[$i]; + $digit = (int) $value[$i]; // Multiply alternate digits by two if ($i % 2 == $parity) { $digit *= 2;