Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Remove too much magic in nested array casting
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Nov 14, 2018
1 parent 371518f commit aab1005
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 18 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 `data-transfer-object` will be documented in this file

## 1.6.2 - 2018-11-14

- Remove too much magic in nested array casting

## 1.6.1 - 2018-11-14

- Support nested `toArray` in collections.
Expand Down
4 changes: 0 additions & 4 deletions src/DataTransferObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ protected function convertForArray($property)
return $property->toArray();
}

if (is_object($property) && method_exists($property, 'toArray')) {
return $property->toArray();
}

if (is_array($property)) {
foreach ($property as $key => $nested) {
$property[$key] = $this->convertForArray($nested);
Expand Down
14 changes: 0 additions & 14 deletions tests/DataTransferTransferObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,5 @@ public function nested_dtos_are_recursive_cast_from_object_to_array_when_to_arra
};

$this->assertEquals(['name' => 'child'], $valueObject->toArray()['childs'][0]);

$object = new class() {
public function toArray()
{
return ['name' => 'custom'];
}
};

$valueObject = new class(['custom' => $object]) extends DataTransferObject {
/** @var mixed */
public $custom;
};

$this->assertEquals(['name' => 'custom'], $valueObject->toArray()['custom']);
}
}

0 comments on commit aab1005

Please sign in to comment.