Skip to content

Commit 06f4793

Browse files
committed
Updates
1 parent 76f5686 commit 06f4793

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

src/Support/Annotations/DataIterableAnnotationReader.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,19 @@ protected function resolveDataClass(
170170
];
171171
}
172172

173-
if (class_exists($class)) {
173+
$fcqn = $this->resolveFcqn($reflection, $class);
174+
175+
if (is_subclass_of($fcqn, BaseData::class)) {
174176
return [
175-
'type' => $class,
176-
'isData' => false,
177+
'type' => $fcqn,
178+
'isData' => true,
177179
];
178180
}
179181

180-
$class = $this->resolveFcqn($reflection, $class);
181-
182-
if (is_subclass_of($class, BaseData::class)) {
182+
if (class_exists($fcqn)) {
183183
return [
184-
'type' => $class,
185-
'isData' => true,
184+
'type' => $fcqn,
185+
'isData' => false,
186186
];
187187
}
188188

tests/Fakes/CollectionNonDataAnnotationsData.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class CollectionNonDataAnnotationsData
5555

5656
public array $propertyO;
5757

58+
/** @var \Illuminate\Support\Collection<Error> */
59+
public Collection $propertyP;
60+
5861
/**
5962
* @param \Spatie\LaravelData\Tests\Fakes\Enums\DummyBackedEnum[]|null $paramA
6063
* @param null|\Spatie\LaravelData\Tests\Fakes\Enums\DummyBackedEnum[] $paramB

tests/Fakes/Error.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Spatie\LaravelData\Tests\Fakes;
4+
5+
use Spatie\LaravelData\Data;
6+
7+
class Error extends Data
8+
{
9+
}

tests/Support/Annotations/DataIterableAnnotationReaderTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Spatie\LaravelData\Tests\Fakes\CollectionDataAnnotationsData;
77
use Spatie\LaravelData\Tests\Fakes\CollectionNonDataAnnotationsData;
88
use Spatie\LaravelData\Tests\Fakes\Enums\DummyBackedEnum;
9+
use Spatie\LaravelData\Tests\Fakes\Error;
910
use Spatie\LaravelData\Tests\Fakes\SimpleData;
1011

1112
it(
@@ -179,6 +180,11 @@ function (string $property, ?DataIterableAnnotation $expected) {
179180
'property' => 'propertyL',
180181
'expected' => new DataIterableAnnotation(DummyBackedEnum::class, isData: false),
181182
];
183+
184+
yield 'propertyP' => [
185+
'property' => 'propertyP',
186+
'expected' => new DataIterableAnnotation(Error::class, isData: true),
187+
];
182188
});
183189

184190
it('can get the iterable class for a collection by class annotation', function () {

0 commit comments

Comments
 (0)