PHP8.5がくるらしい
TL;DR
これを読みなさい
$input = ' Some kind of string. ';
$output = strtolower(
str_replace(['.', '/', '…'], '',
str_replace(' ', '-',
trim($input)
)
)
);
↓
$output = $input
|> trim(...)
|> (fn (string $string) => str_replace(' ', '-', $string))
|> (fn (string $string) => str_replace(['.', '/', '…'], '', $string))
|> strtolower(...);
おしゃれ
ただ結果記述長くなる場合がありそうだし、phpの->methodみたいに呼出すのをヘルパーとかでやるのはどうなんだろ
好みが分かれそう
より詳細
final class Book
{
public function __construct(
public string $title,
public string $description,
) {}
public function withTitle(string $title): self
{
return clone($this, [
'title' => $title,
]);
}
}
🙄