Repository: spatie/data-transfer-object (php)

Issue:
Cannot use positional argument after named argument during unpacking
I found following edge case:

```php
class IssueDTO extends DataTransferObject
{
    public ?ReactionRollupDTO $reactions;
}
```

```php
class ReactionRollupDTO extends DataTransferObject
{
    public int $total_count;

    #[MapFrom('+1')]
    #[MapTo('+1')]
    public int $plus_one;

    #[MapFrom('-1')]
    #[MapTo('-1')]
    public int $minus_one;

    public int $laugh;
}
```

```php
$reactions = [
    'total_count' => 0,
    '+1' => 0,
    -1 => 0,
    'laugh' => 0,
];

// works as expected
dump(new ReactionRollupDTO($reactions));

$issue = [
    'reactions' => $reactions,
];

// Error: Cannot use positional argument after named argument during unpacking
dump(new IssueDTO($issue));
```

Example is how `json_decode` decodes json by default. Not exactly ideal but it is what it is..

I'm aware this could propably be handled with custom caster but my question is if this is something that should be handled in package?

Pull request:
Fix positional after named
This pull request fixes a bug that causes properties mapped from a positional argument to fail after the argument array is unpacked into the casted child DTO. This fixes #298.

Patch:
diff --git a/src/Casters/DataTransferObjectCaster.php b/src/Casters/DataTransferObjectCaster.php
index 4f1913e..6a0383d 100644
--- a/src/Casters/DataTransferObjectCaster.php
+++ b/src/Casters/DataTransferObjectCaster.php
@@ -20,6 +20,6 @@ class DataTransferObjectCaster implements Caster
             }
         }
 
-        return new $this->classNames[0](...$value);
+        return new $this->classNames[0]($value);
     }
 }


Test patch:
diff --git a/tests/MapFromTest.php b/tests/MapFromTest.php
index 240cd8e..cbec422 100644
--- a/tests/MapFromTest.php
+++ b/tests/MapFromTest.php
@@ -102,4 +102,44 @@ class MapFromTest extends TestCase
         $this->assertFalse($dto->isPublic);
         $this->assertEquals(42, $dto->randomInt);
     }
+
+    /** @test */
+    public function dto_can_have_numeric_keys()
+    {
+        $data = [
+            'title' => 'Hello world',
+            '0' => 10,
+        ];
+
+        $dto = new DTOInner($data);
+
+        $this->assertEquals('Hello world', $dto->title);
+        $this->assertEquals(10, $dto->zero);
+    }
+
+    /** @test */
+    public function dto_can_have_numeric_keys_in_nested_dto()
+    {
+        $data = [
+            'innerDTO' => [
+                'title' => 'Hello world',
+                '0' => 10,
+            ],
+        ];
+
+        $dtoOuter = new class ($data) extends DataTransferObject {
+            public DTOInner $innerDTO;
+        };
+
+        $this->assertEquals('Hello world', $dtoOuter->innerDTO->title);
+        $this->assertEquals(10, $dtoOuter->innerDTO->zero);
+    }
+}
+
+class DTOInner extends DataTransferObject
+{
+    public string $title;
+
+    #[MapFrom('0')]
+    public int $zero;
 }