| Total Lines | 76 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 28 | 1 | public static function castUsing(array $arguments) |
|
| 29 | { |
||
| 30 | 1 | return new class ($arguments) implements CastsAttributes { |
|
| 31 | /** |
||
| 32 | * @var array<class-string<TEnum>> |
||
| 33 | */ |
||
| 34 | protected $arguments; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param array<class-string<TEnum>> $arguments |
||
| 38 | */ |
||
| 39 | public function __construct(array $arguments) |
||
| 40 | { |
||
| 41 | 1 | $this->arguments = $arguments; |
|
| 42 | } |
||
| 43 | |||
| 44 | public function get($model, $key, $value, $attributes) |
||
| 45 | { |
||
| 46 | 1 | if (! isset($attributes[$key])) { |
|
| 47 | return; |
||
| 48 | } |
||
| 49 | |||
| 50 | 1 | $data = $attributes[$key]; |
|
| 51 | 1 | if (is_object($data)) { |
|
| 52 | $data = (array) $data; |
||
| 53 | } |
||
| 54 | |||
| 55 | 1 | if (! is_array($data)) { |
|
| 56 | return; |
||
| 57 | } |
||
| 58 | |||
| 59 | 1 | $enumClass = $this->arguments[0]; |
|
| 60 | |||
| 61 | 1 | return (new Collection($data))->map(function ($value) use ($enumClass) { |
|
| 62 | 1 | return is_subclass_of($enumClass, BackedEnum::class) |
|
| 63 | ? $enumClass::from($value) |
||
| 64 | 1 | : constant($enumClass . '::' . $value); |
|
| 65 | 1 | }); |
|
| 66 | } |
||
| 67 | |||
| 68 | public function set($model, $key, $value, $attributes) |
||
| 69 | { |
||
| 70 | 1 | $value = $value !== null |
|
| 71 | 1 | ? (new Collection($value))->map(function ($enum) { |
|
| 72 | 1 | return $this->getStorableEnumValue($enum); |
|
| 73 | 1 | })->jsonSerialize() |
|
| 74 | : null; |
||
| 75 | |||
| 76 | 1 | return [$key => $value]; |
|
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param Model $model |
||
| 81 | * @param string $key |
||
| 82 | * @param mixed $value |
||
| 83 | * @param mixed[] $attributes |
||
| 84 | * @return mixed[] |
||
| 85 | */ |
||
| 86 | public function serialize($model, string $key, $value, array $attributes) |
||
| 87 | { |
||
| 88 | return (new Collection($value))->map(function ($enum) { |
||
| 89 | return $this->getStorableEnumValue($enum); |
||
| 90 | })->toArray(); |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param mixed $enum |
||
| 95 | * @return int|string |
||
| 96 | */ |
||
| 97 | protected function getStorableEnumValue($enum) |
||
| 98 | { |
||
| 99 | 1 | if (is_string($enum) || is_int($enum)) { |
|
| 100 | return $enum; |
||
| 101 | } |
||
| 102 | |||
| 103 | 1 | return $enum instanceof BackedEnum ? $enum->value : $enum->name; |
|
| 104 | } |
||
| 119 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths