Skip to content

Commit 12a928a

Browse files
committed
Clearing data property after DTO validation
1 parent 6b9b239 commit 12a928a

16 files changed

+22
-48
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
/.idea
44
/.vagrant
55
/.phpstorm.*
6+
/.phpunit.cache
67
composer.lock
7-
.phpunit.result.cache
8+
.phpunit.result.cache

src/Attributes/Cast.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ public function __construct(
1818
* @var class-string
1919
*/
2020
public ?string $param = null,
21-
) {
22-
}
21+
) {}
2322
}

src/Attributes/DefaultValue.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ final class DefaultValue
1111
{
1212
public function __construct(
1313
public mixed $value,
14-
) {
15-
}
14+
) {}
1615
}

src/Attributes/Map.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ final class Map
1212
public function __construct(
1313
public ?string $data = null,
1414
public ?string $transform = null,
15-
) {
16-
}
15+
) {}
1716
}

src/Attributes/Rules.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ public function __construct(
1818
* @var array<string, string>
1919
*/
2020
public array $messages = [],
21-
) {
22-
}
21+
) {}
2322
}

src/Casting/ArrayCast.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
final class ArrayCast implements Castable
88
{
9-
public function __construct(private ?Castable $type = null)
10-
{
11-
}
9+
public function __construct(private ?Castable $type = null) {}
1210

1311
public function cast(string $property, mixed $value): array
1412
{

src/Casting/CarbonCast.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ final class CarbonCast implements Castable
1313
public function __construct(
1414
private ?string $timezone = null,
1515
private ?string $format = null
16-
) {
17-
}
16+
) {}
1817

1918
/**
2019
* @throws CastException

src/Casting/CarbonImmutableCast.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ final class CarbonImmutableCast implements Castable
1313
public function __construct(
1414
private ?string $timezone = null,
1515
private ?string $format = null
16-
) {
17-
}
16+
) {}
1817

1918
/**
2019
* @throws CastException

src/Casting/CollectionCast.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
final class CollectionCast implements Castable
1010
{
11-
public function __construct(private ?Castable $type = null)
12-
{
13-
}
11+
public function __construct(private ?Castable $type = null) {}
1412

1513
public function cast(string $property, mixed $value): Collection
1614
{

src/Casting/DTOCast.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
final class DTOCast implements Castable
1414
{
15-
public function __construct(private string $dtoClass)
16-
{
17-
}
15+
public function __construct(private string $dtoClass) {}
1816

1917
/**
2018
* @throws CastException|CastTargetException|ValidationException

src/Casting/EnumCast.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ final class EnumCast implements Castable
1414
/**
1515
* @param class-string<UnitEnum|BackedEnum> $enum
1616
*/
17-
public function __construct(protected string $enum)
18-
{
19-
}
17+
public function __construct(protected string $enum) {}
2018

2119
/**
2220
* @throws CastException|CastTargetException

src/Casting/ModelCast.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
final class ModelCast implements Castable
1313
{
14-
public function __construct(private string $modelClass)
15-
{
16-
}
14+
public function __construct(private string $modelClass) {}
1715

1816
/**
1917
* @throws CastException|CastTargetException

src/SimpleDTO.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ protected function passedValidation(): void
191191
$this->validatedData[$key] = $formatted;
192192
}
193193
}
194+
195+
$this->data = [];
194196
}
195197

196198
protected function failedValidation(): void

src/Support/ResourceCollection.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ public function __construct(
2222
private string $dtoClass,
2323
private int $status = 200,
2424
private array $headers = []
25-
) {
26-
}
25+
) {}
2726

2827
/**
2928
* @param Request $request

tests/Unit/SimpleDTOTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@
108108
= 'test:command
109109
{name : The name of the user}';
110110

111-
public function __invoke()
112-
{
113-
}
111+
public function __invoke() {}
114112
};
115113

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

135-
public function __invoke()
136-
{
137-
}
133+
public function __invoke() {}
138134
};
139135

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

160-
public function __invoke()
161-
{
162-
}
156+
public function __invoke() {}
163157
};
164158

165159
Application::starting(function ($artisan) use ($command) {

tests/Unit/ValidatedDTOTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@
140140
= 'test:command
141141
{name : The name of the user}';
142142

143-
public function __invoke()
144-
{
145-
}
143+
public function __invoke() {}
146144
};
147145

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

169-
public function __invoke()
170-
{
171-
}
167+
public function __invoke() {}
172168
};
173169

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

196-
public function __invoke()
197-
{
198-
}
192+
public function __invoke() {}
199193
};
200194

201195
Application::starting(function ($artisan) use ($command) {

0 commit comments

Comments
 (0)