1 | <?php |
||||||||
2 | |||||||||
3 | declare(strict_types=1); |
||||||||
4 | |||||||||
5 | namespace LaravelFreelancerNL\Aranguent\Eloquent\Casts; |
||||||||
6 | |||||||||
7 | use Illuminate\Contracts\Database\Eloquent\CastsAttributes; |
||||||||
8 | use Illuminate\Database\Eloquent\Casts\ArrayObject; |
||||||||
9 | use Illuminate\Database\Eloquent\Casts\AsArrayObject as IlluminateAsArrayObject; |
||||||||
10 | use LaravelFreelancerNL\Aranguent\Eloquent\Model; |
||||||||
11 | |||||||||
12 | class AsArrayObject extends IlluminateAsArrayObject |
||||||||
13 | { |
||||||||
14 | /** |
||||||||
15 | * Get the caster class to use when casting from / to this cast target. |
||||||||
16 | * |
||||||||
17 | * @param array<array-key, mixed> $arguments |
||||||||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||||||||
18 | * @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Database\Eloquent\Casts\ArrayObject<array-key, mixed>, iterable<array-key, mixed>> |
||||||||
19 | * |
||||||||
20 | * @SuppressWarnings("PHPMD.UnusedFormalParameter") |
||||||||
21 | */ |
||||||||
22 | 1 | public static function castUsing(array $arguments) |
|||||||
23 | { |
||||||||
24 | 1 | return new class implements CastsAttributes { |
|||||||
25 | public function get($model, $key, $value, $attributes) |
||||||||
26 | { |
||||||||
27 | 1 | if (! isset($attributes[$key])) { |
|||||||
28 | return; |
||||||||
29 | } |
||||||||
30 | |||||||||
31 | 1 | $data = $attributes[$key]; |
|||||||
32 | |||||||||
33 | 1 | if (is_object($data)) { |
|||||||
34 | 1 | $data = mapObjectToArray($data); |
|||||||
35 | } |
||||||||
36 | |||||||||
37 | 1 | return is_array($data) ? new ArrayObject($data, ArrayObject::ARRAY_AS_PROPS) : null; |
|||||||
0 ignored issues
–
show
The expression
return is_array($data) ?...:ARRAY_AS_PROPS) : null also could return the type Illuminate\Database\Eloquent\Casts\ArrayObject which is incompatible with the return type mandated by Illuminate\Contracts\Dat...\CastsAttributes::get() of Illuminate\Contracts\Database\Eloquent\TGet|null .
![]() |
|||||||||
38 | } |
||||||||
39 | |||||||||
40 | /** |
||||||||
41 | * @param Model $model |
||||||||
42 | * @param string $key |
||||||||
43 | * @param mixed $value |
||||||||
44 | * @param mixed[] $attributes |
||||||||
45 | * @return mixed[] |
||||||||
46 | * |
||||||||
47 | * @SuppressWarnings("PHPMD.UnusedFormalParameter") |
||||||||
48 | */ |
||||||||
49 | public function set($model, $key, $value, $attributes) |
||||||||
50 | { |
||||||||
51 | 1 | return [$key => $value]; |
|||||||
52 | } |
||||||||
53 | |||||||||
54 | /** |
||||||||
55 | * @param Model $model |
||||||||
56 | * @param string $key |
||||||||
57 | * @param mixed $value |
||||||||
58 | * @param mixed[] $attributes |
||||||||
59 | * @return mixed |
||||||||
60 | */ |
||||||||
61 | public function serialize($model, string $key, $value, array $attributes) |
||||||||
0 ignored issues
–
show
The parameter
$key is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$model is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$attributes is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||
62 | { |
||||||||
63 | return $value->getArrayCopy(); |
||||||||
64 | } |
||||||||
65 | 1 | }; |
|||||||
66 | } |
||||||||
67 | } |
||||||||
68 |