|
13 | 13 |
|
14 | 14 | use Carbon\Carbon; |
15 | 15 | use Carbon\Carbon as Date; |
16 | | -use Countable; |
17 | 16 | use DateTime; |
18 | 17 | use DateTimeInterface; |
19 | 18 | use DateTimeZone; |
@@ -59,7 +58,7 @@ public function validateActiveUrl(string $attribute, $value): bool |
59 | 58 | if ($url = parse_url($value, PHP_URL_HOST)) { |
60 | 59 | try { |
61 | 60 | return count(dns_get_record($url . '.', DNS_A | DNS_AAAA)) > 0; |
62 | | - } catch (Exception $e) { |
| 61 | + } catch (Exception) { |
63 | 62 | return false; |
64 | 63 | } |
65 | 64 | } |
@@ -646,9 +645,7 @@ public function validateInArray(string $attribute, $value, array $parameters): b |
646 | 645 |
|
647 | 646 | $attributeData = ValidationData::extractDataFromPath($explicitPath, $this->data); |
648 | 647 |
|
649 | | - $otherValues = Arr::where(Arr::dot($attributeData), function ($value, $key) use ($parameters) { |
650 | | - return Str::is($parameters[0], $key); |
651 | | - }); |
| 648 | + $otherValues = Arr::where(Arr::dot($attributeData), fn ($value, $key) => Str::is($parameters[0], $key)); |
652 | 649 |
|
653 | 650 | return in_array($value, $otherValues); |
654 | 651 | } |
@@ -872,7 +869,7 @@ public function validateRequired(string $attribute, $value): bool |
872 | 869 | if (is_string($value) && trim($value) === '') { |
873 | 870 | return false; |
874 | 871 | } |
875 | | - if ((is_array($value) || $value instanceof Countable) && count($value) < 1) { |
| 872 | + if ((is_countable($value)) && count($value) < 1) { |
876 | 873 | return false; |
877 | 874 | } |
878 | 875 | if ($value instanceof SplFileInfo) { |
@@ -1057,7 +1054,7 @@ public function validateTimezone(string $attribute, $value): bool |
1057 | 1054 | { |
1058 | 1055 | try { |
1059 | 1056 | new DateTimeZone($value); |
1060 | | - } catch (Throwable $e) { |
| 1057 | + } catch (Throwable) { |
1061 | 1058 | return false; |
1062 | 1059 | } |
1063 | 1060 |
|
@@ -1177,9 +1174,8 @@ protected function getDateFormat(string $attribute) |
1177 | 1174 | * Get the date timestamp. |
1178 | 1175 | * |
1179 | 1176 | * @param mixed $value |
1180 | | - * @return bool|int |
1181 | 1177 | */ |
1182 | | - protected function getDateTimestamp($value) |
| 1178 | + protected function getDateTimestamp($value): bool|int |
1183 | 1179 | { |
1184 | 1180 | if ($value instanceof DateTimeInterface) { |
1185 | 1181 | return $value->getTimestamp(); |
@@ -1240,7 +1236,7 @@ protected function getDateTime(string $value) |
1240 | 1236 | } |
1241 | 1237 |
|
1242 | 1238 | return new DateTime($value); |
1243 | | - } catch (Exception $e) { |
| 1239 | + } catch (Exception) { |
1244 | 1240 | } |
1245 | 1241 | } |
1246 | 1242 |
|
@@ -1318,9 +1314,7 @@ protected function extractDistinctValues(string $attribute): array |
1318 | 1314 |
|
1319 | 1315 | $pattern = str_replace('\*', '[^.]+', preg_quote($attribute, '#')); |
1320 | 1316 |
|
1321 | | - return Arr::where(Arr::dot($attributeData), function ($value, $key) use ($pattern) { |
1322 | | - return (bool) preg_match('#^' . $pattern . '\z#u', $key); |
1323 | | - }); |
| 1317 | + return Arr::where(Arr::dot($attributeData), fn ($value, $key) => (bool) preg_match('#^' . $pattern . '\z#u', $key)); |
1324 | 1318 | } |
1325 | 1319 |
|
1326 | 1320 | /** |
@@ -1474,9 +1468,8 @@ protected function allFailingRequired(array $attributes): bool |
1474 | 1468 | * Get the size of an attribute. |
1475 | 1469 | * |
1476 | 1470 | * @param mixed $value |
1477 | | - * @return float|int |
1478 | 1471 | */ |
1479 | | - protected function getSize(string $attribute, $value) |
| 1472 | + protected function getSize(string $attribute, $value): float|int|string |
1480 | 1473 | { |
1481 | 1474 | $hasNumeric = $this->hasRule($attribute, $this->numericRules); |
1482 | 1475 |
|
@@ -1506,20 +1499,14 @@ protected function getSize(string $attribute, $value) |
1506 | 1499 | */ |
1507 | 1500 | protected function compare($first, $second, string $operator): bool |
1508 | 1501 | { |
1509 | | - switch ($operator) { |
1510 | | - case '<': |
1511 | | - return $first < $second; |
1512 | | - case '>': |
1513 | | - return $first > $second; |
1514 | | - case '<=': |
1515 | | - return $first <= $second; |
1516 | | - case '>=': |
1517 | | - return $first >= $second; |
1518 | | - case '=': |
1519 | | - return $first == $second; |
1520 | | - default: |
1521 | | - throw new InvalidArgumentException(); |
1522 | | - } |
| 1502 | + return match ($operator) { |
| 1503 | + '<' => $first < $second, |
| 1504 | + '>' => $first > $second, |
| 1505 | + '<=' => $first <= $second, |
| 1506 | + '>=' => $first >= $second, |
| 1507 | + '=' => $first == $second, |
| 1508 | + default => throw new InvalidArgumentException(), |
| 1509 | + }; |
1523 | 1510 | } |
1524 | 1511 |
|
1525 | 1512 | /** |
|
0 commit comments