Skip to content

Commit

Permalink
Merge pull request #79 from WendellAdriel/feat/drop-unmapped-data
Browse files Browse the repository at this point in the history
Clearing data property after DTO validation
  • Loading branch information
WendellAdriel authored Jul 12, 2024
2 parents 6b9b239 + 12a928a commit 7a33667
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
/.idea
/.vagrant
/.phpstorm.*
/.phpunit.cache
composer.lock
.phpunit.result.cache
.phpunit.result.cache
3 changes: 1 addition & 2 deletions src/Attributes/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ public function __construct(
* @var class-string
*/
public ?string $param = null,
) {
}
) {}
}
3 changes: 1 addition & 2 deletions src/Attributes/DefaultValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ final class DefaultValue
{
public function __construct(
public mixed $value,
) {
}
) {}
}
3 changes: 1 addition & 2 deletions src/Attributes/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ final class Map
public function __construct(
public ?string $data = null,
public ?string $transform = null,
) {
}
) {}
}
3 changes: 1 addition & 2 deletions src/Attributes/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ public function __construct(
* @var array<string, string>
*/
public array $messages = [],
) {
}
) {}
}
4 changes: 1 addition & 3 deletions src/Casting/ArrayCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

final class ArrayCast implements Castable
{
public function __construct(private ?Castable $type = null)
{
}
public function __construct(private ?Castable $type = null) {}

public function cast(string $property, mixed $value): array
{
Expand Down
3 changes: 1 addition & 2 deletions src/Casting/CarbonCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ final class CarbonCast implements Castable
public function __construct(
private ?string $timezone = null,
private ?string $format = null
) {
}
) {}

/**
* @throws CastException
Expand Down
3 changes: 1 addition & 2 deletions src/Casting/CarbonImmutableCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ final class CarbonImmutableCast implements Castable
public function __construct(
private ?string $timezone = null,
private ?string $format = null
) {
}
) {}

/**
* @throws CastException
Expand Down
4 changes: 1 addition & 3 deletions src/Casting/CollectionCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

final class CollectionCast implements Castable
{
public function __construct(private ?Castable $type = null)
{
}
public function __construct(private ?Castable $type = null) {}

public function cast(string $property, mixed $value): Collection
{
Expand Down
4 changes: 1 addition & 3 deletions src/Casting/DTOCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

final class DTOCast implements Castable
{
public function __construct(private string $dtoClass)
{
}
public function __construct(private string $dtoClass) {}

/**
* @throws CastException|CastTargetException|ValidationException
Expand Down
4 changes: 1 addition & 3 deletions src/Casting/EnumCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ final class EnumCast implements Castable
/**
* @param class-string<UnitEnum|BackedEnum> $enum
*/
public function __construct(protected string $enum)
{
}
public function __construct(protected string $enum) {}

/**
* @throws CastException|CastTargetException
Expand Down
4 changes: 1 addition & 3 deletions src/Casting/ModelCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

final class ModelCast implements Castable
{
public function __construct(private string $modelClass)
{
}
public function __construct(private string $modelClass) {}

/**
* @throws CastException|CastTargetException
Expand Down
2 changes: 2 additions & 0 deletions src/SimpleDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ protected function passedValidation(): void
$this->validatedData[$key] = $formatted;
}
}

$this->data = [];
}

protected function failedValidation(): void
Expand Down
3 changes: 1 addition & 2 deletions src/Support/ResourceCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public function __construct(
private string $dtoClass,
private int $status = 200,
private array $headers = []
) {
}
) {}

/**
* @param Request $request
Expand Down
12 changes: 3 additions & 9 deletions tests/Unit/SimpleDTOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@
= 'test:command
{name : The name of the user}';

public function __invoke()
{
}
public function __invoke() {}
};

Application::starting(function ($artisan) use ($command) {
Expand All @@ -132,9 +130,7 @@ public function __invoke()
= 'test:command
{--name= : The name of the user}';

public function __invoke()
{
}
public function __invoke() {}
};

Application::starting(function ($artisan) use ($command) {
Expand All @@ -157,9 +153,7 @@ public function __invoke()
{name : The name of the user}
{--age= : The age of the user}';

public function __invoke()
{
}
public function __invoke() {}
};

Application::starting(function ($artisan) use ($command) {
Expand Down
12 changes: 3 additions & 9 deletions tests/Unit/ValidatedDTOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@
= 'test:command
{name : The name of the user}';

public function __invoke()
{
}
public function __invoke() {}
};

Application::starting(function ($artisan) use ($command) {
Expand All @@ -166,9 +164,7 @@ public function __invoke()
= 'test:command
{--name= : The name of the user}';

public function __invoke()
{
}
public function __invoke() {}
};

Application::starting(function ($artisan) use ($command) {
Expand All @@ -193,9 +189,7 @@ public function __invoke()
{name : The name of the user}
{--age= : The age of the user}';

public function __invoke()
{
}
public function __invoke() {}
};

Application::starting(function ($artisan) use ($command) {
Expand Down

0 comments on commit 7a33667

Please sign in to comment.