Skip to content

Commit

Permalink
Merge branch 'main' of github.com:spatie/laravel-data-resource
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Sep 10, 2024
2 parents f87b25a + 6a7ed95 commit 1b7c105
Show file tree
Hide file tree
Showing 30 changed files with 32 additions and 40 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/as-a-data-transfer-object/request-to-data-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/validation/using-validation-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Dimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(

public function getRule(ValidationPath $path): object|string
{
if($this->rule) {
if ($this->rule) {
return $this->rule;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(

public function getRule(ValidationPath $path): object|string
{
if($this->rule) {
if ($this->rule) {
return $this->rule;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/NotIn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Unique.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(

public function getRule(ValidationPath $path): object|string
{
if($this->rule) {
if ($this->rule) {
return $this->rule;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Casts/EnumerableCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Casts/UnserializeCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/DataStructuresCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/DataPipes/CastPropertiesDataPipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected function castIterableItems(
array $properties,
CreationContext $creationContext
): array {
if(empty($values)) {
if (empty($values)) {
return $values;
}

Expand Down
2 changes: 1 addition & 1 deletion src/DataPipes/DefaultValuesDataPipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/LaravelDataServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resolvers/DataCollectableFromSomethingResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function normalizeItems(
return $payload;
}

if($items === null) {
if ($items === null) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Resolvers/DataFromArrayResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Resolvers/NameMappersResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Resolvers/VisibleDataFieldsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ protected function handleNonExistingNestedField(
throw $exception;
}

if(config('data.ignore_invalid_partials')) {
if (config('data.ignore_invalid_partials')) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/RuleInferrers/AttributesRuleInferrer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Support/Annotations/CollectionAnnotationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Support/Creation/GlobalCastsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Support/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function acceptsType(string $type): bool

public function getAcceptedTypes(): array
{
if($this->isMixed) {
if ($this->isMixed) {
return [];
}

Expand Down
8 changes: 4 additions & 4 deletions src/Support/Transformation/DataContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function mergeTransformationContext(
foreach ($context->includePartials as $partial) {
$partial = $decoupledPartialResolver->execute($partial);

if($partial !== null) {
if ($partial !== null) {
$this->includePartials->attach($partial);
}
}
Expand All @@ -70,7 +70,7 @@ public function mergeTransformationContext(
foreach ($context->excludePartials as $partial) {
$partial = $decoupledPartialResolver->execute($partial);

if($partial !== null) {
if ($partial !== null) {
$this->excludePartials->attach($partial);
}
}
Expand All @@ -82,7 +82,7 @@ public function mergeTransformationContext(
foreach ($context->onlyPartials as $partial) {
$partial = $decoupledPartialResolver->execute($partial);

if($partial !== null) {
if ($partial !== null) {
$this->onlyPartials->attach($partial);
}
}
Expand All @@ -94,7 +94,7 @@ public function mergeTransformationContext(
foreach ($context->exceptPartials as $partial) {
$partial = $decoupledPartialResolver->execute($partial);

if($partial !== null) {
if ($partial !== null) {
$this->exceptPartials->attach($partial);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Validation/RuleDenormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fakes/ComplicatedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[] */
Expand Down
1 change: 0 additions & 1 deletion tests/Fakes/Transformers/ConfidentialDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use function collect;

use Spatie\LaravelData\Support\DataProperty;

use Spatie\LaravelData\Support\Transformation\TransformationContext;
use Spatie\LaravelData\Transformers\Transformer;

Expand Down
1 change: 0 additions & 1 deletion tests/FillRouteParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion tests/LivewireTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions tests/TestSupport/DataValidationAsserter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1b7c105

Please sign in to comment.