Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Support/Annotations/DataIterableAnnotationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,19 @@ protected function resolveDataClass(
];
}

if (class_exists($class)) {
$fcqn = $this->resolveFcqn($reflection, $class);

if (is_subclass_of($fcqn, BaseData::class)) {
return [
'type' => $class,
'isData' => false,
'type' => $fcqn,
'isData' => true,
];
}

$class = $this->resolveFcqn($reflection, $class);

if (is_subclass_of($class, BaseData::class)) {
if (class_exists($fcqn)) {
return [
'type' => $class,
'isData' => true,
'type' => $fcqn,
'isData' => false,
];
}

Expand Down
3 changes: 3 additions & 0 deletions tests/Fakes/CollectionNonDataAnnotationsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class CollectionNonDataAnnotationsData

public array $propertyO;

/** @var \Illuminate\Support\Collection<Error> */
public Collection $propertyP;

/**
* @param \Spatie\LaravelData\Tests\Fakes\Enums\DummyBackedEnum[]|null $paramA
* @param null|\Spatie\LaravelData\Tests\Fakes\Enums\DummyBackedEnum[] $paramB
Expand Down
9 changes: 9 additions & 0 deletions tests/Fakes/Error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Spatie\LaravelData\Tests\Fakes;

use Spatie\LaravelData\Data;

class Error extends Data
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Spatie\LaravelData\Tests\Fakes\CollectionDataAnnotationsData;
use Spatie\LaravelData\Tests\Fakes\CollectionNonDataAnnotationsData;
use Spatie\LaravelData\Tests\Fakes\Enums\DummyBackedEnum;
use Spatie\LaravelData\Tests\Fakes\Error;
use Spatie\LaravelData\Tests\Fakes\SimpleData;

it(
Expand Down Expand Up @@ -179,6 +180,11 @@ function (string $property, ?DataIterableAnnotation $expected) {
'property' => 'propertyL',
'expected' => new DataIterableAnnotation(DummyBackedEnum::class, isData: false),
];

yield 'propertyP' => [
'property' => 'propertyP',
'expected' => new DataIterableAnnotation(Error::class, isData: true),
];
});

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