From 2188c25f01f153fa25b46efd9a52965e38135e0b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 3 Feb 2017 20:37:08 +0100 Subject: [PATCH] Type fixes --- Datatypes/Location.php | 2 +- Localization/Money.php | 2 +- Math/Number/Numbers.php | 4 +++- Math/Number/Prime.php | 4 ++-- Message/ResponseAbstract.php | 2 +- Security/Encryption/Encryption.php | 4 ++-- System/File/Local/FileAbstract.php | 4 ++-- Uri/Http.php | 2 +- Utils/Parser/Php/MemberParser.php | 2 +- 9 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Datatypes/Location.php b/Datatypes/Location.php index 8862812d8..45f9788cc 100644 --- a/Datatypes/Location.php +++ b/Datatypes/Location.php @@ -241,7 +241,7 @@ class Location implements \JsonSerializable, \Serializable */ public function serialize() { - return $this->jsonSerialize(); + return json_encode($this->jsonSerialize()); } /** diff --git a/Localization/Money.php b/Localization/Money.php index 5944a5d5f..a54b6435a 100644 --- a/Localization/Money.php +++ b/Localization/Money.php @@ -200,7 +200,7 @@ class Money implements \Serializable $left = substr($value, 0, -self::MAX_DECIMALS); $right = substr($value, -self::MAX_DECIMALS); - return ($decimals > 0) ? number_format($left, 0, $this->decimal, $this->thousands) . $this->decimal . substr($right, 0, $decimals) : (string) $left; + return ($decimals > 0) ? number_format((float) $left, 0, $this->decimal, $this->thousands) . $this->decimal . substr($right, 0, $decimals) : (string) $left; } /** diff --git a/Math/Number/Numbers.php b/Math/Number/Numbers.php index 6f6849899..259849641 100644 --- a/Math/Number/Numbers.php +++ b/Math/Number/Numbers.php @@ -65,9 +65,11 @@ class Numbers */ public static function isSelfdescribing(int $n) : bool { + $n = (string) $n; $split = str_split($n); + foreach ($split as $place => $value) { - if (substr_count($n, $place) != $value) { + if (substr_count($n, (string) $place) != $value) { return false; } } diff --git a/Math/Number/Prime.php b/Math/Number/Prime.php index c109c8417..01cff7de9 100644 --- a/Math/Number/Prime.php +++ b/Math/Number/Prime.php @@ -94,14 +94,14 @@ class Prime for ($i = 0; $i < $k; $i++) { $a = mt_rand(2, $n - 1); - $x = bcpowmod($a, $d, $n); + $x = bcpowmod((string) $a, (string) $d, (string) $n); if ($x == 1 || $x == $n - 1) { continue; } for ($j = 1; $j < $s; $j++) { - $x = bcmod(bcmul($x, $x), $n); + $x = bcmod(bcmul($x, $x), (string) $n); if ($x == 1) { return false; diff --git a/Message/ResponseAbstract.php b/Message/ResponseAbstract.php index 8b0ed56b4..e69639d91 100644 --- a/Message/ResponseAbstract.php +++ b/Message/ResponseAbstract.php @@ -111,7 +111,7 @@ abstract class ResponseAbstract implements MessageInterface, \JsonSerializable */ public function set($key, $response, bool $overwrite = true) /* : void */ { - $this->response = ArrayUtils::setArray($key, $this->response, $response, ':', $overwrite); + $this->response = ArrayUtils::setArray((string) $key, $this->response, $response, ':', $overwrite); } /** diff --git a/Security/Encryption/Encryption.php b/Security/Encryption/Encryption.php index e41e5f249..4c8978cc7 100644 --- a/Security/Encryption/Encryption.php +++ b/Security/Encryption/Encryption.php @@ -390,7 +390,7 @@ class Encryption { $pad = ord($value[($len = strlen($value)) - 1]); - return $this->paddingIsValid($pad, $value) ? substr($value, 0, $len - $pad) : $value; + return $this->paddingIsValid((string) $pad, $value) ? substr($value, 0, $len - $pad) : $value; } /** @@ -408,7 +408,7 @@ class Encryption { $beforePad = strlen($value) - $pad; - return substr($value, $beforePad) == str_repeat(substr($value, -1), $pad); + return substr($value, $beforePad) == str_repeat(substr($value, -1), (int) $pad); } /** diff --git a/System/File/Local/FileAbstract.php b/System/File/Local/FileAbstract.php index c6311fda1..57274f2ac 100644 --- a/System/File/Local/FileAbstract.php +++ b/System/File/Local/FileAbstract.php @@ -95,7 +95,7 @@ abstract class FileAbstract implements ContainerInterface * @var string * @since 1.0.0 */ - protected $permission = '0000'; + protected $permission = 0644; /** * Constructor. @@ -194,6 +194,6 @@ abstract class FileAbstract implements ContainerInterface $this->createdAt->setTimestamp(filemtime($this->path)); $this->changedAt->setTimestamp(filectime($this->path)); $this->owner = fileowner($this->path); - $this->permission = substr(sprintf('%o', fileperms($this->path)), -4); + $this->permission = (int) substr(sprintf('%o', fileperms($this->path)), -4); } } \ No newline at end of file diff --git a/Uri/Http.php b/Uri/Http.php index 75addff71..b6362eb4e 100644 --- a/Uri/Http.php +++ b/Uri/Http.php @@ -193,7 +193,7 @@ class Http implements UriInterface */ public static function isValid(string $uri) : bool { - return filter_var($uri, FILTER_VALIDATE_URL); + return (bool) filter_var($uri, FILTER_VALIDATE_URL); } /** diff --git a/Utils/Parser/Php/MemberParser.php b/Utils/Parser/Php/MemberParser.php index 19f16be8e..ea34e4190 100644 --- a/Utils/Parser/Php/MemberParser.php +++ b/Utils/Parser/Php/MemberParser.php @@ -252,7 +252,7 @@ class MemberParser } elseif (is_string($value)) { return '"' . $value . '"'; } elseif (is_scalar($value)) { - return $value; + return (string) $value; } elseif (is_null($value)) { return 'null'; } elseif (is_bool($value)) {