diff --git a/src/Attributes/Validation/Exclude.php b/src/Attributes/Validation/Exclude.php index 15cf1276a..6f83a6a5f 100644 --- a/src/Attributes/Validation/Exclude.php +++ b/src/Attributes/Validation/Exclude.php @@ -9,13 +9,13 @@ #[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Exclude extends ObjectValidationAttribute { - public function __construct(protected ExcludeIf $rule) + public function __construct(protected ?ExcludeIf $rule = null) { } public function getRule(ValidationPath $path): object|string { - return $this->rule; + return $this->rule ?? self::keyword(); } public static function keyword(): string diff --git a/src/Attributes/Validation/ValidationAttribute.php b/src/Attributes/Validation/ValidationAttribute.php index cbc3e110b..4c4e8eef2 100644 --- a/src/Attributes/Validation/ValidationAttribute.php +++ b/src/Attributes/Validation/ValidationAttribute.php @@ -46,11 +46,11 @@ protected static function parseBooleanValue(mixed $value): mixed } if ($value === 'true' || $value === '1') { - return true; + return 'true'; } if ($value === 'false' || $value === '0') { - return true; + return 'false'; } return $value; diff --git a/src/Casts/UnserializeCast.php b/src/Casts/UnserializeCast.php index db3ffc311..d06686bb4 100644 --- a/src/Casts/UnserializeCast.php +++ b/src/Casts/UnserializeCast.php @@ -8,7 +8,7 @@ class UnserializeCast implements Cast { public function __construct( - private bool $failSilently = false, + private readonly bool $failSilently = false, ) { } diff --git a/src/Commands/DataMakeCommand.php b/src/Commands/DataMakeCommand.php index 075c51fac..a828dc9b0 100644 --- a/src/Commands/DataMakeCommand.php +++ b/src/Commands/DataMakeCommand.php @@ -39,7 +39,7 @@ protected function qualifyClass($name): string { $suffix = trim($this->option('suffix')); if (! empty($suffix) && ! Str::endsWith($name, $suffix)) { - $name = $name . $suffix; + $name .= $suffix; } return parent::qualifyClass($name); diff --git a/src/Concerns/AppendableData.php b/src/Concerns/AppendableData.php index 07e336aa1..98595f4af 100644 --- a/src/Concerns/AppendableData.php +++ b/src/Concerns/AppendableData.php @@ -24,13 +24,10 @@ public function getAdditionalData(): array { $additional = $this->with(); - $computedAdditional = []; - - foreach ($additional as $name => $value) { - $computedAdditional[$name] = $value instanceof Closure - ? ($value)($this) - : $value; - } + $computedAdditional = array_map( + fn ($value) => $value instanceof Closure ? ($value)($this) : $value, + $additional + ); foreach ($this->_additional as $name => $value) { $computedAdditional[$name] = $value instanceof Closure diff --git a/src/Concerns/ValidateableData.php b/src/Concerns/ValidateableData.php index b48716e4f..d4ad96ff7 100644 --- a/src/Concerns/ValidateableData.php +++ b/src/Concerns/ValidateableData.php @@ -41,7 +41,6 @@ public static function validateAndCreate(Arrayable|array $payload): static public static function withValidator(Validator $validator): void { - return; } public static function getValidationRules(array $payload): array diff --git a/src/DataPipes/CastPropertiesDataPipe.php b/src/DataPipes/CastPropertiesDataPipe.php index b13d5ce65..95967a501 100644 --- a/src/DataPipes/CastPropertiesDataPipe.php +++ b/src/DataPipes/CastPropertiesDataPipe.php @@ -129,7 +129,7 @@ protected function cast( protected function shouldBeCasted(DataProperty $property, mixed $value): bool { - if (gettype($value) !== 'object') { + if (!is_object($value)) { return true; } diff --git a/src/DataPipes/DefaultValuesDataPipe.php b/src/DataPipes/DefaultValuesDataPipe.php index 38ab18086..1d4474f6c 100644 --- a/src/DataPipes/DefaultValuesDataPipe.php +++ b/src/DataPipes/DefaultValuesDataPipe.php @@ -33,8 +33,6 @@ public function handle( if ($property->type->isNullable) { $properties[$name] = null; - - continue; } } diff --git a/src/Exceptions/CannotPerformPartialOnDataField.php b/src/Exceptions/CannotPerformPartialOnDataField.php index 15e478691..c06326d5e 100644 --- a/src/Exceptions/CannotPerformPartialOnDataField.php +++ b/src/Exceptions/CannotPerformPartialOnDataField.php @@ -19,7 +19,7 @@ public static function create( ): self { $message = "Tried to {$partialType->getVerb()} a non existing field `{$field}` on `{$dataClass->name}`.".PHP_EOL; $message .= 'Provided transformation context:'.PHP_EOL.PHP_EOL; - $message .= (string) $transformationContext; + $message .= $transformationContext; return new self(message: $message, previous: $exception); } diff --git a/src/Resolvers/DataValidationMessagesAndAttributesResolver.php b/src/Resolvers/DataValidationMessagesAndAttributesResolver.php index dac90ba14..69d8919f9 100644 --- a/src/Resolvers/DataValidationMessagesAndAttributesResolver.php +++ b/src/Resolvers/DataValidationMessagesAndAttributesResolver.php @@ -45,8 +45,9 @@ public function execute( [...$nestingChain, $dataProperty->type->dataClass], ); - $messages = array_merge($messages, $nested['messages']); - $attributes = array_merge($attributes, $nested['attributes']); + + $messages[] = $nested['messages']; + $attributes[] = $nested['attributes']; continue; } @@ -63,13 +64,14 @@ public function execute( [...$nestingChain, $dataProperty->type->dataClass], ); - $messages = array_merge($messages, $collected['messages']); - $attributes = array_merge($attributes, $collected['attributes']); - - continue; + $messages[] = $collected['messages']; + $attributes[] = $collected['attributes']; } } + $messages = array_merge(...$messages); + $attributes = array_merge(...$attributes); + if (method_exists($class, 'messages')) { $messages = collect(app()->call([$class, 'messages'])) ->keyBy( diff --git a/src/Resolvers/EmptyDataResolver.php b/src/Resolvers/EmptyDataResolver.php index 3509d2467..0749f13be 100644 --- a/src/Resolvers/EmptyDataResolver.php +++ b/src/Resolvers/EmptyDataResolver.php @@ -34,7 +34,7 @@ public function execute(string $class, array $extra = []): array return $payload; } - protected function getValueForProperty(DataProperty $property): mixed + protected function getValueForProperty(DataProperty $property): ?array { $propertyType = $property->type; diff --git a/src/Resolvers/RequestQueryStringPartialsResolver.php b/src/Resolvers/RequestQueryStringPartialsResolver.php index ead50f690..1ff34e4b7 100644 --- a/src/Resolvers/RequestQueryStringPartialsResolver.php +++ b/src/Resolvers/RequestQueryStringPartialsResolver.php @@ -151,10 +151,6 @@ protected function findField( $outputMappedProperties = $dataClass->outputMappedProperties->resolve(); - if (array_key_exists($field, $outputMappedProperties)) { - return $outputMappedProperties[$field]; - } - - return null; + return $outputMappedProperties[$field] ?? null; } } diff --git a/src/Resolvers/TransformedDataCollectableResolver.php b/src/Resolvers/TransformedDataCollectableResolver.php index d3b0f458a..c889a2bf8 100644 --- a/src/Resolvers/TransformedDataCollectableResolver.php +++ b/src/Resolvers/TransformedDataCollectableResolver.php @@ -75,11 +75,10 @@ protected function transformItems( bool $executeWrap, TransformationContext $nestedContext, ): array { - $collection = []; - - foreach ($items as $key => $value) { - $collection[$key] = $this->transformationClosure($nestedContext)($value); - } + $collection = array_map( + fn ($value) => $this->transformationClosure($nestedContext)($value), + is_array($items) ? $items : $items->all() + ); return $executeWrap ? $wrap->wrap($collection) diff --git a/src/Support/Caching/DataStructureCache.php b/src/Support/Caching/DataStructureCache.php index 0968cdc1f..88a5e948f 100644 --- a/src/Support/Caching/DataStructureCache.php +++ b/src/Support/Caching/DataStructureCache.php @@ -27,9 +27,7 @@ public function getConfig(): ?CachedDataConfig /** @var ?CachedDataConfig $cachedConfig */ $cachedConfig = $this->get('config'); - if ($cachedConfig) { - $cachedConfig->setCache($this); - } + $cachedConfig?->setCache($this); return $cachedConfig; } diff --git a/src/Support/Creation/CreationContext.php b/src/Support/Creation/CreationContext.php index f7de00662..d87516bee 100644 --- a/src/Support/Creation/CreationContext.php +++ b/src/Support/Creation/CreationContext.php @@ -78,7 +78,7 @@ public function next( ): self { $this->dataClass = $dataClass; - array_push($this->currentPath, $path); + $this->currentPath[] = $path; return $this; } diff --git a/src/Support/DataConfig.php b/src/Support/DataConfig.php index fa2a0a30f..946bdc877 100644 --- a/src/Support/DataConfig.php +++ b/src/Support/DataConfig.php @@ -15,7 +15,7 @@ public static function createFromConfig(array $config): static $dataClasses = []; $ruleInferrers = array_map( - fn (string $ruleInferrerClass) => app($ruleInferrerClass), + app(...), $config['rule_inferrers'] ?? [] ); diff --git a/src/Support/EloquentCasts/DataEloquentCast.php b/src/Support/EloquentCasts/DataEloquentCast.php index 6e7095736..551587d70 100644 --- a/src/Support/EloquentCasts/DataEloquentCast.php +++ b/src/Support/EloquentCasts/DataEloquentCast.php @@ -74,7 +74,6 @@ public function set($model, string $key, $value, array $attributes): ?string 'data' => json_decode($value->toJson(), associative: true, flags: JSON_THROW_ON_ERROR), ]) : $value->toJson(); - ; if (in_array('encrypted', $this->arguments)) { return Crypt::encryptString($value); diff --git a/src/Support/Partials/Partial.php b/src/Support/Partials/Partial.php index 82c6c9291..18c337dff 100644 --- a/src/Support/Partials/Partial.php +++ b/src/Support/Partials/Partial.php @@ -90,7 +90,7 @@ protected static function resolveSegmentsFromPath(string $path): array substr($segmentString, 1, -1) ); - $segments[] = new FieldsPartialSegment(array_map(fn (string $field) => trim($field), $fields)); + $segments[] = new FieldsPartialSegment(array_map(trim(...), $fields)); return $segments; } diff --git a/src/Support/Transformation/GlobalTransformersCollection.php b/src/Support/Transformation/GlobalTransformersCollection.php index 29ca499e1..a00a32b27 100644 --- a/src/Support/Transformation/GlobalTransformersCollection.php +++ b/src/Support/Transformation/GlobalTransformersCollection.php @@ -26,7 +26,7 @@ public function add(string $transformable, Transformer $transformer): self public function findTransformerForValue(mixed $value): ?Transformer { - if (gettype($value) !== 'object') { + if (!is_object($value)) { return $this->transformers[get_debug_type($value)] ?? null; }