From 6385351054b1b232fcb856a9b0e40a1a65919ca7 Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Sat, 6 Nov 2021 10:18:05 -0300 Subject: [PATCH] [9.0] Change some switch to match --- .../Eloquent/Concerns/HasAttributes.php | 16 +++++--------- .../Database/Schema/Grammars/ChangeColumn.php | 13 +++++------ .../Http/Middleware/ValidatePostSize.php | 16 +++++--------- .../Concerns/ValidatesAttributes.php | 22 +++++++------------ .../Validation/ValidationRuleParser.php | 13 +++++------ 5 files changed, 30 insertions(+), 50 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index 0c469e4e6e8a..6e99499626fe 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php @@ -994,16 +994,12 @@ public static function encryptUsing($encrypter) */ public function fromFloat($value) { - switch ((string) $value) { - case 'Infinity': - return INF; - case '-Infinity': - return -INF; - case 'NaN': - return NAN; - default: - return (float) $value; - } + return match ((string) $value) { + 'Infinity' => INF, + '-Infinity' => -INF, + 'NaN' => NAN, + default => (float) $value, + }; } /** diff --git a/src/Illuminate/Database/Schema/Grammars/ChangeColumn.php b/src/Illuminate/Database/Schema/Grammars/ChangeColumn.php index 260935f8a71e..d55f731c5fc1 100644 --- a/src/Illuminate/Database/Schema/Grammars/ChangeColumn.php +++ b/src/Illuminate/Database/Schema/Grammars/ChangeColumn.php @@ -175,14 +175,11 @@ protected static function getDoctrineColumnType($type) */ protected static function calculateDoctrineTextLength($type) { - switch ($type) { - case 'mediumText': - return 65535 + 1; - case 'longText': - return 16777215 + 1; - default: - return 255 + 1; - } + return match ($type) { + 'mediumText' => 65535 + 1, + 'longText' => 16777215 + 1, + default => 255 + 1, + }; } /** diff --git a/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php b/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php index adc5f5a3f2dd..512b822e0a63 100644 --- a/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php +++ b/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php @@ -41,15 +41,11 @@ protected function getPostMaxSize() $metric = strtoupper(substr($postMaxSize, -1)); $postMaxSize = (int) $postMaxSize; - switch ($metric) { - case 'K': - return $postMaxSize * 1024; - case 'M': - return $postMaxSize * 1048576; - case 'G': - return $postMaxSize * 1073741824; - default: - return $postMaxSize; - } + return match ($metric) { + 'K' => $postMaxSize * 1024, + 'M' => $postMaxSize * 1048576, + 'G' => $postMaxSize * 1073741824, + default => $postMaxSize, + }; } } diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index c7d7bb959ee0..7c0cfbdce01c 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -1992,20 +1992,14 @@ public function isValidFileInstance($value) */ protected function compare($first, $second, $operator) { - switch ($operator) { - case '<': - return $first < $second; - case '>': - return $first > $second; - case '<=': - return $first <= $second; - case '>=': - return $first >= $second; - case '=': - return $first == $second; - default: - throw new InvalidArgumentException; - } + return match ($operator) { + '<' => $first < $second, + '>' => $first > $second, + '<=' => $first <= $second, + '>=' => $first >= $second, + '=' => $first == $second, + default => throw new InvalidArgumentException, + }; } /** diff --git a/src/Illuminate/Validation/ValidationRuleParser.php b/src/Illuminate/Validation/ValidationRuleParser.php index ce499a55a58c..cecb25ce469d 100644 --- a/src/Illuminate/Validation/ValidationRuleParser.php +++ b/src/Illuminate/Validation/ValidationRuleParser.php @@ -265,14 +265,11 @@ protected static function parseParameters($rule, $parameter) */ protected static function normalizeRule($rule) { - switch ($rule) { - case 'Int': - return 'Integer'; - case 'Bool': - return 'Boolean'; - default: - return $rule; - } + return match ($rule) { + 'Int' => 'Integer', + 'Bool' => 'Boolean', + default => $rule, + }; } /**