Skip to content

Commit

Permalink
Fix issue with data property
Browse files Browse the repository at this point in the history
  • Loading branch information
WendellAdriel committed Nov 5, 2024
1 parent cb418e0 commit 0ed6764
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/SimpleDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ abstract class SimpleDTO implements BaseDTO, CastsAttributes
{
use DataResolver, DataTransformer;

protected array $data = [];
/** @internal */
protected array $dtoData = [];

protected array $validatedData = [];

Expand Down Expand Up @@ -63,7 +64,7 @@ public function __construct(?array $data = null)
}

$this->buildAttributesData();
$this->data = $this->buildDataForValidation($data);
$this->dtoData = $this->buildDataForValidation($data);

$this->initConfig();

Expand Down Expand Up @@ -193,7 +194,7 @@ protected function passedValidation(): void
}
}

$this->data = [];
$this->dtoData = [];
}

protected function failedValidation(): void
Expand All @@ -219,7 +220,7 @@ protected function validatedData(): array
/** @var array<Castable> $casts */
$casts = $this->buildCasts();

foreach ($this->data as $key => $value) {
foreach ($this->dtoData as $key => $value) {
if (in_array($key, $acceptedKeys)) {
if (! array_key_exists($key, $casts)) {
if ($this->requireCasting) {
Expand Down Expand Up @@ -514,7 +515,7 @@ private function getAcceptedProperties(): array
private function isforbiddenProperty(string $property): bool
{
return in_array($property, [
'data',
'dtoData',
'validatedData',
'requireCasting',
'validator',
Expand Down
4 changes: 2 additions & 2 deletions src/ValidatedDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function validatedData(): array
/** @var array<Castable> $casts */
$casts = $this->buildCasts();

foreach ($this->data as $key => $value) {
foreach ($this->dtoData as $key => $value) {
if (in_array($key, $acceptedKeys)) {
if (! array_key_exists($key, $casts)) {
if ($this->requireCasting) {
Expand Down Expand Up @@ -83,7 +83,7 @@ protected function validatedData(): array
protected function isValidData(): bool
{
$this->validator = Validator::make(
$this->data,
$this->dtoData,
$this->rulesList(),
$this->messagesList(),
$this->attributes()
Expand Down

0 comments on commit 0ed6764

Please sign in to comment.