Skip to content

Commit 67a890f

Browse files
authored
use multiline parameters for casting methods (#10345)
I find the side scrolling for code snippets to decrease readability. these lengthy method signatures are often the culprit on this page. switching to multiline parameters to help avoid the necessity to side scroll. followed the PSR-12 recommendation for when dealing with multiline parameters AND a return type.
1 parent 509ebaa commit 67a890f

File tree

1 file changed

+48
-16
lines changed

1 file changed

+48
-16
lines changed

eloquent-mutators.md

+48-16
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,12 @@ class AsJson implements CastsAttributes
690690
* @param array<string, mixed> $attributes
691691
* @return array<string, mixed>
692692
*/
693-
public function get(Model $model, string $key, mixed $value, array $attributes): array
694-
{
693+
public function get(
694+
Model $model,
695+
string $key,
696+
mixed $value,
697+
array $attributes,
698+
): array {
695699
return json_decode($value, true);
696700
}
697701

@@ -700,8 +704,12 @@ class AsJson implements CastsAttributes
700704
*
701705
* @param array<string, mixed> $attributes
702706
*/
703-
public function set(Model $model, string $key, mixed $value, array $attributes): string
704-
{
707+
public function set(
708+
Model $model,
709+
string $key,
710+
mixed $value,
711+
array $attributes,
712+
): string {
705713
return json_encode($value);
706714
}
707715
}
@@ -757,8 +765,12 @@ class AsAddress implements CastsAttributes
757765
*
758766
* @param array<string, mixed> $attributes
759767
*/
760-
public function get(Model $model, string $key, mixed $value, array $attributes): Address
761-
{
768+
public function get(
769+
Model $model,
770+
string $key,
771+
mixed $value,
772+
array $attributes,
773+
): Address {
762774
return new Address(
763775
$attributes['address_line_one'],
764776
$attributes['address_line_two']
@@ -771,8 +783,12 @@ class AsAddress implements CastsAttributes
771783
* @param array<string, mixed> $attributes
772784
* @return array<string, string>
773785
*/
774-
public function set(Model $model, string $key, mixed $value, array $attributes): array
775-
{
786+
public function set(
787+
Model $model,
788+
string $key,
789+
mixed $value,
790+
array $attributes,
791+
): array {
776792
if (! $value instanceof Address) {
777793
throw new InvalidArgumentException('The given value is not an Address instance.');
778794
}
@@ -829,8 +845,12 @@ Therefore, you may specify that your custom cast class will be responsible for s
829845
*
830846
* @param array<string, mixed> $attributes
831847
*/
832-
public function serialize(Model $model, string $key, mixed $value, array $attributes): string
833-
{
848+
public function serialize(
849+
Model $model,
850+
string $key,
851+
mixed $value,
852+
array $attributes,
853+
): string {
834854
return (string) $value;
835855
}
836856
```
@@ -870,8 +890,12 @@ class AsHash implements CastsInboundAttributes
870890
*
871891
* @param array<string, mixed> $attributes
872892
*/
873-
public function set(Model $model, string $key, mixed $value, array $attributes): string
874-
{
893+
public function set(
894+
Model $model,
895+
string $key,
896+
mixed $value,
897+
array $attributes,
898+
): string {
875899
return is_null($this->algorithm)
876900
? bcrypt($value)
877901
: hash($this->algorithm, $value);
@@ -977,16 +1001,24 @@ class Address implements Castable
9771001
{
9781002
return new class implements CastsAttributes
9791003
{
980-
public function get(Model $model, string $key, mixed $value, array $attributes): Address
981-
{
1004+
public function get(
1005+
Model $model,
1006+
string $key,
1007+
mixed $value,
1008+
array $attributes,
1009+
): Address {
9821010
return new Address(
9831011
$attributes['address_line_one'],
9841012
$attributes['address_line_two']
9851013
);
9861014
}
9871015

988-
public function set(Model $model, string $key, mixed $value, array $attributes): array
989-
{
1016+
public function set(
1017+
Model $model,
1018+
string $key,
1019+
mixed $value,
1020+
array $attributes,
1021+
): array {
9901022
return [
9911023
'address_line_one' => $value->lineOne,
9921024
'address_line_two' => $value->lineTwo,

0 commit comments

Comments
 (0)