Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
cerbero90 committed Oct 25, 2024
1 parent dea5f37 commit e5a53ec
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/CasesCollectionCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function get(Model $model, string $key, mixed $value, array $attributes):
{
return match (true) {
is_string($value) => $this->getByJson($value),
/** @phpstan-ignore-next-line binaryOp.invalid */
is_int($value) => $this->enum::filter(fn(BackedEnum $case) => ($value & $case->value) == $case->value),
default => null,
};
Expand Down Expand Up @@ -79,7 +80,7 @@ public function set(Model $model, string $key, mixed $value, array $attributes):
$this->withoutObjectCaching = ! $value instanceof CasesCollection;

return match (true) {
$value instanceof CasesCollection => $value->toJson(),
$value instanceof CasesCollection => $value->toJson() ?: null,
is_array($value) => $this->setByArray($value),
is_int($value) => $value,
default => null,
Expand All @@ -94,7 +95,7 @@ public function set(Model $model, string $key, mixed $value, array $attributes):
protected function setByArray(array $array): string|int|null
{
if (is_subclass_of($this->enum, Bitwise::class)) {
return array_reduce($array, function(?int $carry, BackedEnum|int $item) {
return array_reduce($array, function (?int $carry, mixed $item): int {
return $carry |= $item instanceof BackedEnum ? $item->value : $item;
});
}
Expand Down

0 comments on commit e5a53ec

Please sign in to comment.