From cf23f7641d49d01dd63f6b1ef788d6acc6d2e4c8 Mon Sep 17 00:00:00 2001 From: rubenvanassche Date: Fri, 30 Aug 2024 13:59:02 +0000 Subject: [PATCH 1/4] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5270c2cf..351abacf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `laravel-data` will be documented in this file. +## 4.8.2 - 2024-08-30 + +- Remove a circular dependency + ## 4.81 - 2024-08-13 - Fix a missing dependency From 75664614a57f4b566f789cfca525e78acfdb735e Mon Sep 17 00:00:00 2001 From: Dishan Sachin <134765302+skdishansachin@users.noreply.github.com> Date: Sat, 7 Sep 2024 21:32:28 +0530 Subject: [PATCH 2/4] corrected link to the validation page --- docs/as-a-data-transfer-object/request-to-data-object.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/as-a-data-transfer-object/request-to-data-object.md b/docs/as-a-data-transfer-object/request-to-data-object.md index 1252f953..e0994370 100644 --- a/docs/as-a-data-transfer-object/request-to-data-object.md +++ b/docs/as-a-data-transfer-object/request-to-data-object.md @@ -63,7 +63,7 @@ class UpdateSongController } ``` -We have a complete section within these docs dedicated to validation, you can find it [here](/docs/laravel-data/v4/validation). +We have a complete section within these docs dedicated to validation, you can find it [here](/docs/laravel-data/v4/validation/introduction). ## Getting the data object filled with request data from anywhere From 8466bd7eb6855f2a59538867d8a60bb685bb9010 Mon Sep 17 00:00:00 2001 From: rubenvanassche Date: Mon, 9 Sep 2024 06:46:40 +0000 Subject: [PATCH 3/4] Fix styling --- src/Attributes/Validation/Dimensions.php | 2 +- src/Attributes/Validation/Exists.php | 2 +- src/Attributes/Validation/NotIn.php | 2 +- src/Attributes/Validation/Unique.php | 2 +- src/Casts/EnumerableCast.php | 4 ++-- src/Casts/UnserializeCast.php | 2 +- src/Commands/DataStructuresCacheCommand.php | 2 +- src/DataPipes/CastPropertiesDataPipe.php | 2 +- src/DataPipes/DefaultValuesDataPipe.php | 2 +- src/LaravelDataServiceProvider.php | 2 +- src/Resolvers/DataCollectableFromSomethingResolver.php | 2 +- src/Resolvers/DataFromArrayResolver.php | 2 +- src/Resolvers/NameMappersResolver.php | 2 +- src/Resolvers/VisibleDataFieldsResolver.php | 2 +- src/RuleInferrers/AttributesRuleInferrer.php | 2 +- src/Support/Annotations/CollectionAnnotationReader.php | 2 +- src/Support/Creation/GlobalCastsCollection.php | 4 ++-- src/Support/DataType.php | 2 +- src/Support/Transformation/DataContext.php | 8 ++++---- src/Support/Validation/RuleDenormalizer.php | 2 +- tests/Fakes/ComplicatedData.php | 2 +- tests/Fakes/Transformers/ConfidentialDataTransformer.php | 1 - tests/FillRouteParametersTest.php | 1 - tests/LivewireTest.php | 1 - .../EloquentCasts/DataCollectionEloquentCastTest.php | 3 --- tests/TestSupport/DataValidationAsserter.php | 4 ---- tests/ValidationTest.php | 2 -- 27 files changed, 26 insertions(+), 38 deletions(-) diff --git a/src/Attributes/Validation/Dimensions.php b/src/Attributes/Validation/Dimensions.php index 544aa2dd..4f49b3dc 100644 --- a/src/Attributes/Validation/Dimensions.php +++ b/src/Attributes/Validation/Dimensions.php @@ -38,7 +38,7 @@ public function __construct( public function getRule(ValidationPath $path): object|string { - if($this->rule) { + if ($this->rule) { return $this->rule; } diff --git a/src/Attributes/Validation/Exists.php b/src/Attributes/Validation/Exists.php index b1aca89e..f441d181 100644 --- a/src/Attributes/Validation/Exists.php +++ b/src/Attributes/Validation/Exists.php @@ -28,7 +28,7 @@ public function __construct( public function getRule(ValidationPath $path): object|string { - if($this->rule) { + if ($this->rule) { return $this->rule; } diff --git a/src/Attributes/Validation/NotIn.php b/src/Attributes/Validation/NotIn.php index ab0248ab..ecedb439 100644 --- a/src/Attributes/Validation/NotIn.php +++ b/src/Attributes/Validation/NotIn.php @@ -22,7 +22,7 @@ public function __construct(array|string|BaseNotIn|RouteParameterReference ...$v public function getRule(ValidationPath $path): object|string { - if($this->rule) { + if ($this->rule) { return $this->rule; } diff --git a/src/Attributes/Validation/Unique.php b/src/Attributes/Validation/Unique.php index 9833aca7..7db5e18f 100644 --- a/src/Attributes/Validation/Unique.php +++ b/src/Attributes/Validation/Unique.php @@ -30,7 +30,7 @@ public function __construct( public function getRule(ValidationPath $path): object|string { - if($this->rule) { + if ($this->rule) { return $this->rule; } diff --git a/src/Casts/EnumerableCast.php b/src/Casts/EnumerableCast.php index 681d70dd..cf3f47b4 100644 --- a/src/Casts/EnumerableCast.php +++ b/src/Casts/EnumerableCast.php @@ -11,11 +11,11 @@ class EnumerableCast implements Cast { public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): mixed { - if(config('data.features.cast_and_transform_iterables')) { + if (config('data.features.cast_and_transform_iterables')) { return Uncastable::create(); } - if($property->type->kind->isDataCollectable()) { + if ($property->type->kind->isDataCollectable()) { return Uncastable::create(); } diff --git a/src/Casts/UnserializeCast.php b/src/Casts/UnserializeCast.php index d1716901..db3ffc31 100644 --- a/src/Casts/UnserializeCast.php +++ b/src/Casts/UnserializeCast.php @@ -22,7 +22,7 @@ public function cast(DataProperty $property, mixed $value, array $properties, Cr try { return unserialize($value); } catch (\Throwable $e) { - if($this->failSilently) { + if ($this->failSilently) { return Uncastable::create(); } diff --git a/src/Commands/DataStructuresCacheCommand.php b/src/Commands/DataStructuresCacheCommand.php index 58a660c4..e7f52305 100644 --- a/src/Commands/DataStructuresCacheCommand.php +++ b/src/Commands/DataStructuresCacheCommand.php @@ -19,7 +19,7 @@ public function handle( DataStructureCache $dataStructureCache, DataClassFactory $dataClassFactory, ): void { - if(config('data.structure_caching.enabled') === false) { + if (config('data.structure_caching.enabled') === false) { $this->error('Data structure caching is not enabled'); return; diff --git a/src/DataPipes/CastPropertiesDataPipe.php b/src/DataPipes/CastPropertiesDataPipe.php index 00ea616f..b13d5ce6 100644 --- a/src/DataPipes/CastPropertiesDataPipe.php +++ b/src/DataPipes/CastPropertiesDataPipe.php @@ -175,7 +175,7 @@ protected function castIterableItems( array $properties, CreationContext $creationContext ): array { - if(empty($values)) { + if (empty($values)) { return $values; } diff --git a/src/DataPipes/DefaultValuesDataPipe.php b/src/DataPipes/DefaultValuesDataPipe.php index 0a3964f6..38ab1808 100644 --- a/src/DataPipes/DefaultValuesDataPipe.php +++ b/src/DataPipes/DefaultValuesDataPipe.php @@ -15,7 +15,7 @@ public function handle( CreationContext $creationContext ): array { foreach ($class->properties as $name => $property) { - if(array_key_exists($name, $properties)) { + if (array_key_exists($name, $properties)) { continue; } diff --git a/src/LaravelDataServiceProvider.php b/src/LaravelDataServiceProvider.php index 748fe8db..77463369 100644 --- a/src/LaravelDataServiceProvider.php +++ b/src/LaravelDataServiceProvider.php @@ -57,7 +57,7 @@ function () { ); }); - if(config('data.livewire.enable_synths') && class_exists(Livewire::class)) { + if (config('data.livewire.enable_synths') && class_exists(Livewire::class)) { $this->registerLivewireSynths(); } } diff --git a/src/Resolvers/DataCollectableFromSomethingResolver.php b/src/Resolvers/DataCollectableFromSomethingResolver.php index 6b1e2067..292f1425 100644 --- a/src/Resolvers/DataCollectableFromSomethingResolver.php +++ b/src/Resolvers/DataCollectableFromSomethingResolver.php @@ -151,7 +151,7 @@ protected function normalizeItems( return $payload; } - if($items === null) { + if ($items === null) { return []; } diff --git a/src/Resolvers/DataFromArrayResolver.php b/src/Resolvers/DataFromArrayResolver.php index 827ca3f8..825ded0c 100644 --- a/src/Resolvers/DataFromArrayResolver.php +++ b/src/Resolvers/DataFromArrayResolver.php @@ -31,7 +31,7 @@ public function execute(string $class, array $properties): BaseData $data = $this->createData($dataClass, $properties); foreach ($dataClass->properties as $property) { - if( + if ( $property->isPromoted || $property->isReadonly || ! array_key_exists($property->name, $properties) diff --git a/src/Resolvers/NameMappersResolver.php b/src/Resolvers/NameMappersResolver.php index 943726d1..67be0a54 100644 --- a/src/Resolvers/NameMappersResolver.php +++ b/src/Resolvers/NameMappersResolver.php @@ -76,7 +76,7 @@ protected function resolveMapperClass(int|string|NameMapper $value): NameMapper return new ProvidedNameMapper($value); } - if($value instanceof NameMapper) { + if ($value instanceof NameMapper) { return $value; } diff --git a/src/Resolvers/VisibleDataFieldsResolver.php b/src/Resolvers/VisibleDataFieldsResolver.php index d75eea1b..ccbf95b7 100644 --- a/src/Resolvers/VisibleDataFieldsResolver.php +++ b/src/Resolvers/VisibleDataFieldsResolver.php @@ -307,7 +307,7 @@ protected function handleNonExistingNestedField( throw $exception; } - if(config('data.ignore_invalid_partials')) { + if (config('data.ignore_invalid_partials')) { return; } diff --git a/src/RuleInferrers/AttributesRuleInferrer.php b/src/RuleInferrers/AttributesRuleInferrer.php index dd0d104c..ed0896d9 100644 --- a/src/RuleInferrers/AttributesRuleInferrer.php +++ b/src/RuleInferrers/AttributesRuleInferrer.php @@ -25,7 +25,7 @@ public function handle( ->attributes ->filter(fn (object $attribute) => $attribute instanceof ValidationRule) ->each(function (ValidationRule $rule) use ($rules) { - if($rule instanceof Present && $rules->hasType(RequiringRule::class)) { + if ($rule instanceof Present && $rules->hasType(RequiringRule::class)) { $rules->removeType(RequiringRule::class); } diff --git a/src/Support/Annotations/CollectionAnnotationReader.php b/src/Support/Annotations/CollectionAnnotationReader.php index b45bf6c8..9187c385 100644 --- a/src/Support/Annotations/CollectionAnnotationReader.php +++ b/src/Support/Annotations/CollectionAnnotationReader.php @@ -36,7 +36,7 @@ public function getForClass(string $className): ?CollectionAnnotation $class = new ReflectionClass($className); - if(empty($class->getDocComment())) { + if (empty($class->getDocComment())) { return self::$cache[$className] = null; } diff --git a/src/Support/Creation/GlobalCastsCollection.php b/src/Support/Creation/GlobalCastsCollection.php index ae549a5e..e230593c 100644 --- a/src/Support/Creation/GlobalCastsCollection.php +++ b/src/Support/Creation/GlobalCastsCollection.php @@ -27,11 +27,11 @@ public function add(string $castable, Cast|IterableItemCast $cast): self { $castable = ltrim($castable, ' \\'); - if($cast instanceof Cast) { + if ($cast instanceof Cast) { $this->casts[$castable] = $cast; } - if($cast instanceof IterableItemCast) { + if ($cast instanceof IterableItemCast) { $this->iterableItemCasts[$castable] = $cast; } diff --git a/src/Support/DataType.php b/src/Support/DataType.php index ea485f21..aae50d7e 100644 --- a/src/Support/DataType.php +++ b/src/Support/DataType.php @@ -31,7 +31,7 @@ public function acceptsType(string $type): bool public function getAcceptedTypes(): array { - if($this->isMixed) { + if ($this->isMixed) { return []; } diff --git a/src/Support/Transformation/DataContext.php b/src/Support/Transformation/DataContext.php index f754d596..98e72e2a 100644 --- a/src/Support/Transformation/DataContext.php +++ b/src/Support/Transformation/DataContext.php @@ -59,7 +59,7 @@ public function mergeTransformationContext( foreach ($context->includePartials as $partial) { $partial = $decoupledPartialResolver->execute($partial); - if($partial !== null) { + if ($partial !== null) { $this->includePartials->attach($partial); } } @@ -71,7 +71,7 @@ public function mergeTransformationContext( foreach ($context->excludePartials as $partial) { $partial = $decoupledPartialResolver->execute($partial); - if($partial !== null) { + if ($partial !== null) { $this->excludePartials->attach($partial); } } @@ -83,7 +83,7 @@ public function mergeTransformationContext( foreach ($context->onlyPartials as $partial) { $partial = $decoupledPartialResolver->execute($partial); - if($partial !== null) { + if ($partial !== null) { $this->onlyPartials->attach($partial); } } @@ -95,7 +95,7 @@ public function mergeTransformationContext( foreach ($context->exceptPartials as $partial) { $partial = $decoupledPartialResolver->execute($partial); - if($partial !== null) { + if ($partial !== null) { $this->exceptPartials->attach($partial); } } diff --git a/src/Support/Validation/RuleDenormalizer.php b/src/Support/Validation/RuleDenormalizer.php index cce8eb13..84bd6fdf 100644 --- a/src/Support/Validation/RuleDenormalizer.php +++ b/src/Support/Validation/RuleDenormalizer.php @@ -39,7 +39,7 @@ public function execute(mixed $rule, ValidationPath $path): array return [$rule->getRule($path)]; } - if($rule instanceof CustomValidationAttribute) { + if ($rule instanceof CustomValidationAttribute) { return Arr::wrap($rule->getRules($path)); } diff --git a/tests/Fakes/ComplicatedData.php b/tests/Fakes/ComplicatedData.php index ebad51e3..db08db5b 100644 --- a/tests/Fakes/ComplicatedData.php +++ b/tests/Fakes/ComplicatedData.php @@ -24,7 +24,7 @@ public function __construct( public int|Optional $undefinable, public mixed $mixed, #[WithCast(DateTimeInterfaceCast::class, format: 'd-m-Y', type: CarbonImmutable::class)] - public $explicitCast, + public $explicitCast, public DateTime $defaultCast, public ?SimpleData $nestedData, /** @var \Spatie\LaravelData\Tests\Fakes\SimpleData[] */ diff --git a/tests/Fakes/Transformers/ConfidentialDataTransformer.php b/tests/Fakes/Transformers/ConfidentialDataTransformer.php index 677470ac..98cad090 100644 --- a/tests/Fakes/Transformers/ConfidentialDataTransformer.php +++ b/tests/Fakes/Transformers/ConfidentialDataTransformer.php @@ -5,7 +5,6 @@ use function collect; use Spatie\LaravelData\Support\DataProperty; - use Spatie\LaravelData\Support\Transformation\TransformationContext; use Spatie\LaravelData\Transformers\Transformer; diff --git a/tests/FillRouteParametersTest.php b/tests/FillRouteParametersTest.php index 66c726ca..13986c26 100644 --- a/tests/FillRouteParametersTest.php +++ b/tests/FillRouteParametersTest.php @@ -6,7 +6,6 @@ use function Pest\Laravel\mock; use Spatie\LaravelData\Attributes\FromRouteParameter; - use Spatie\LaravelData\Attributes\FromRouteParameterProperty; use Spatie\LaravelData\Attributes\MapInputName; use Spatie\LaravelData\Data; diff --git a/tests/LivewireTest.php b/tests/LivewireTest.php index 61f62bf6..6ab4981d 100644 --- a/tests/LivewireTest.php +++ b/tests/LivewireTest.php @@ -7,7 +7,6 @@ use Spatie\LaravelData\Concerns\WireableData; use Spatie\LaravelData\Data; - use Spatie\LaravelData\Lazy; use Spatie\LaravelData\Support\Livewire\LivewireDataCollectionSynth; use Spatie\LaravelData\Support\Livewire\LivewireDataSynth; diff --git a/tests/Support/EloquentCasts/DataCollectionEloquentCastTest.php b/tests/Support/EloquentCasts/DataCollectionEloquentCastTest.php index 30ed128a..97efc5d1 100644 --- a/tests/Support/EloquentCasts/DataCollectionEloquentCastTest.php +++ b/tests/Support/EloquentCasts/DataCollectionEloquentCastTest.php @@ -7,11 +7,8 @@ use Spatie\LaravelData\DataCollection; use Spatie\LaravelData\Tests\Fakes\AbstractData\AbstractData; use Spatie\LaravelData\Tests\Fakes\AbstractData\AbstractDataA; - use Spatie\LaravelData\Tests\Fakes\AbstractData\AbstractDataB; - use Spatie\LaravelData\Tests\Fakes\Models\DummyModelWithCasts; - use Spatie\LaravelData\Tests\Fakes\Models\DummyModelWithCustomCollectionCasts; use Spatie\LaravelData\Tests\Fakes\Models\DummyModelWithDefaultCasts; use Spatie\LaravelData\Tests\Fakes\SimpleData; diff --git a/tests/TestSupport/DataValidationAsserter.php b/tests/TestSupport/DataValidationAsserter.php index dd3da335..0da2bd9d 100644 --- a/tests/TestSupport/DataValidationAsserter.php +++ b/tests/TestSupport/DataValidationAsserter.php @@ -8,18 +8,14 @@ use function PHPUnit\Framework\assertTrue; use Spatie\LaravelData\Data; - use Spatie\LaravelData\DataPipeline; - use Spatie\LaravelData\DataPipes\MapPropertiesDataPipe; - use Spatie\LaravelData\DataPipes\ValidatePropertiesDataPipe; use Spatie\LaravelData\Normalizers\ArrayNormalizer; use Spatie\LaravelData\Resolvers\DataValidationRulesResolver; use Spatie\LaravelData\Resolvers\DataValidatorResolver; use Spatie\LaravelData\Support\Creation\CreationContextFactory; use Spatie\LaravelData\Support\Validation\DataRules; - use Spatie\LaravelData\Support\Validation\ValidationPath; /** diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 19ae857b..a61a1674 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -18,9 +18,7 @@ use function PHPUnit\Framework\assertFalse; use Spatie\LaravelData\Attributes\DataCollectionOf; - use Spatie\LaravelData\Attributes\MapInputName; - use Spatie\LaravelData\Attributes\MapName; use Spatie\LaravelData\Attributes\Validation\ArrayType; use Spatie\LaravelData\Attributes\Validation\Bail; From 6a7ed95aafbaa56a43d70ffdec50574b6a67b9ef Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Mon, 9 Sep 2024 11:17:55 +0200 Subject: [PATCH 4/4] Update using-validation-attributes.md --- docs/validation/using-validation-attributes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/validation/using-validation-attributes.md b/docs/validation/using-validation-attributes.md index a53ab3a8..93ff32a2 100644 --- a/docs/validation/using-validation-attributes.md +++ b/docs/validation/using-validation-attributes.md @@ -29,7 +29,7 @@ So it is not required to add the `required` and `string` rule, these will be add ] ``` -For each Laravel validation rule we've got a matching validation attribute, you can find a list of them [here](/docs/laravel-data/v4/advanced-usage/using-attributes). +For each Laravel validation rule we've got a matching validation attribute, you can find a list of them [here](/docs/laravel-data/v4/advanced-usage/validation-attributes). ## Referencing route parameters