From b82213d97f135ceea6348dd89d19ca746b417a9a Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 18 Jul 2018 00:12:53 +0200 Subject: [PATCH] Turn some returns into exceptions --- DataStorage/Database/GrammarAbstract.php | 12 ++++++------ .../Database/Schema/Exception/TableException.php | 2 +- Localization/Money.php | 4 ++-- Uri/Http.php | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/DataStorage/Database/GrammarAbstract.php b/DataStorage/Database/GrammarAbstract.php index c55d09abe..7b85dfcd9 100644 --- a/DataStorage/Database/GrammarAbstract.php +++ b/DataStorage/Database/GrammarAbstract.php @@ -95,7 +95,7 @@ abstract class GrammarAbstract { return trim( implode(' ', - array_filter( + \array_filter( $this->compileComponents($query), function ($value) { return (string) $value !== ''; @@ -169,13 +169,13 @@ abstract class GrammarAbstract $expression = ''; foreach ($elements as $key => $element) { - if (is_string($element) && $element !== '*') { - if (strpos($element, '.') === false) { + if (\is_string($element) && $element !== '*') { + if (\strpos($element, '.') === false) { $prefix = ''; } $expression .= $this->compileSystem($element, $prefix) . ', '; - } elseif (is_string($element) && $element === '*') { + } elseif (\is_string($element) && $element === '*') { $expression .= '*, '; } elseif ($element instanceof \Closure) { $expression .= $element() . ', '; @@ -204,9 +204,9 @@ abstract class GrammarAbstract $expression = ''; foreach ($elements as $key => $element) { - if (is_string($element) && $element !== '*') { + if (\is_string($element) && $element !== '*') { $expression .= $this->compileSystem($element, $prefix) . ', '; - } elseif (is_string($element) && $element === '*') { + } elseif (\is_string($element) && $element === '*') { $expression .= '*, '; } elseif ($element instanceof \Closure) { $expression .= $element() . ', '; diff --git a/DataStorage/Database/Schema/Exception/TableException.php b/DataStorage/Database/Schema/Exception/TableException.php index 7fa34c155..98f82d800 100644 --- a/DataStorage/Database/Schema/Exception/TableException.php +++ b/DataStorage/Database/Schema/Exception/TableException.php @@ -63,6 +63,6 @@ class TableException extends \PDOException $table = \substr($message, $pos1 + 1, $pos2 - $pos1 - 1); - return $table === false ? '' : $table; + return $table === false ? $message : $table; } } diff --git a/Localization/Money.php b/Localization/Money.php index df1410dbd..16b0639cb 100644 --- a/Localization/Money.php +++ b/Localization/Money.php @@ -122,7 +122,7 @@ final class Money implements \Serializable $right = \substr($right, 0, self::MAX_DECIMALS); if ($right === false) { - return 0; + throw new \Exception(); } return ((int) $left) * 10 ** self::MAX_DECIMALS + (int) \str_pad($right, self::MAX_DECIMALS, '0'); @@ -196,7 +196,7 @@ final class Money implements \Serializable $left = \substr($value, 0, -self::MAX_DECIMALS); $right = \substr($value, -self::MAX_DECIMALS); if ($left === false || $right === false) { - return '0'; + throw new \Exception(); } return ($decimals > 0) ? number_format((float) $left, 0, $this->decimal, $this->thousands) . $this->decimal . \substr($right, 0, $decimals) : $left; diff --git a/Uri/Http.php b/Uri/Http.php index 25f4afd9a..79b47cccd 100644 --- a/Uri/Http.php +++ b/Uri/Http.php @@ -158,7 +158,7 @@ final class Http implements UriInterface $path = \substr($this->path, 0, -4); if ($path === false) { - return; + throw new \Exception(); } $this->path = $path;