Skip to content

Commit

Permalink
multiple early returns to match
Browse files Browse the repository at this point in the history
  • Loading branch information
shaedrich committed Dec 16, 2024
1 parent 2af3abc commit 09acfd4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
13 changes: 6 additions & 7 deletions src/Illuminate/Http/Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -991,13 +991,12 @@ protected function parseHttpOptions(array $options)
$options[$this->bodyFormat] = $this->pendingBody;
}

return (new Collection($options))->map(function ($value, $key) {
if ($key === 'json' && $value instanceof JsonSerializable) {
return $value;
}

return $value instanceof Arrayable ? $value->toArray() : $value;
})->all();
return (new Collection($options))
->map(fn ($value, $key) => match (true) {
$key === 'json' && $value instanceof JsonSerializable => $value,
$value instanceof Arrayable => $value->toArray(),
default => $value,
})->all();
}

/**
Expand Down
11 changes: 5 additions & 6 deletions src/Illuminate/Http/Middleware/SetCacheHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ public static function using($options)
}

return (new Collection($options))
->map(function ($value, $key) {
if (is_bool($value)) {
return $value ? $key : null;
}

return is_int($key) ? $value : "{$key}={$value}";
->map(fn ($value, $key) => match (true) {
$value === true => $key,
$value === false => null,
is_int($key) => $value,
default => "{$key}={$value}",
})
->filter()
->map(fn ($value) => Str::finish($value, ';'))
Expand Down
23 changes: 8 additions & 15 deletions src/Illuminate/Mail/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,14 @@ protected function addAddresses($address, $name, $type)
if (is_array($address)) {
$type = lcfirst($type);

$addresses = (new Collection($address))->map(function ($address, $key) {
if (is_string($key) && is_string($address)) {
return new Address($key, $address);
}

if (is_array($address)) {
return new Address($address['email'] ?? $address['address'], $address['name'] ?? null);
}

if (is_null($address)) {
return new Address($key);
}

return $address;
})->all();
$addresses = (new Collection($address))
->map(fn ($address, $key) => match (true) {
is_string($key) && is_string($address) => new Address($key, $address),
is_array($address) => new Address($address['email'] ?? $address['address'], $address['name'] ?? null),
is_null($address) => new Address($key),
default => $address,
})
->all();

$this->message->{"{$type}"}(...$addresses);
} else {
Expand Down

0 comments on commit 09acfd4

Please sign in to comment.