Skip to content

Commit

Permalink
[9.0] Change some switch to match (#39504)
Browse files Browse the repository at this point in the history
  • Loading branch information
KennedyTedesco authored Nov 6, 2021
1 parent 7f6fb00 commit fcb7acb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 50 deletions.
16 changes: 6 additions & 10 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1038,16 +1038,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,
};
}

/**
Expand Down
13 changes: 5 additions & 8 deletions src/Illuminate/Database/Schema/Grammars/ChangeColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

/**
Expand Down
16 changes: 6 additions & 10 deletions src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
}
22 changes: 8 additions & 14 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

/**
Expand Down
13 changes: 5 additions & 8 deletions src/Illuminate/Validation/ValidationRuleParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

/**
Expand Down

0 comments on commit fcb7acb

Please sign in to comment.