Skip to content

Commit a08a702

Browse files
committed
Remove STI and MTI implementations
These features reached blocker limitations for future designs and will be re-planned from scratch later.
1 parent c7ab409 commit a08a702

21 files changed

Lines changed: 106 additions & 618 deletions

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ parameters:
44
- src/
55
- tests/
66
ignoreErrors:
7-
- message: '/Call to an undefined (static )?method Respect\\Data\\(AbstractMapper|InMemoryMapper|Collections\\(Collection|Composite|Typed))::\w+\(\)\./'
7+
- message: '/Call to an undefined (static )?method Respect\\Data\\(AbstractMapper|InMemoryMapper|Collections\\Collection)::\w+\(\)\./'
88
- message: '/Unsafe usage of new static\(\)\./'
99
-
1010
message: '/Property .+ is never read, only written\./'

src/Collections/Collection.php

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,12 @@ public function derive(
3737
): static {
3838
return new static(
3939
$this->name,
40-
...$this->deriveArgs(
41-
with: $with,
42-
filter: $filter,
43-
required: $required,
44-
),
40+
with: [...$this->with, ...$with],
41+
filter: $filter ?? $this->filter,
42+
required: $required ?? $this->required,
4543
);
4644
}
4745

48-
/**
49-
* @param list<Collection> $with
50-
* @param array<scalar, mixed>|scalar|null $filter
51-
*
52-
* @return array{with: list<Collection>, filter: array|int|float|string|bool|null, required: bool}
53-
*/
54-
protected function deriveArgs( // @phpstan-ignore missingType.iterableValue
55-
array $with = [],
56-
array|int|float|string|bool|null $filter = null,
57-
bool|null $required = null,
58-
): array {
59-
return [
60-
'with' => [...$this->with, ...$with],
61-
'filter' => $filter ?? $this->filter,
62-
'required' => $required ?? $this->required,
63-
];
64-
}
65-
6646
/**
6747
* @param list<Collection> $children
6848
*

src/Collections/Composite.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/Collections/Typed.php

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/EntityFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function extractProperties(object $entity): array
192192
$props = [];
193193

194194
foreach ($this->reflectProperties($entity::class) as $name => $prop) {
195-
if (!$prop->isInitialized($entity) || $prop->getAttributes(NotPersistable::class)) {
195+
if ($prop->isVirtual() || !$prop->isInitialized($entity) || $prop->getAttributes(NotPersistable::class)) {
196196
continue;
197197
}
198198

@@ -218,7 +218,7 @@ public function enumerateFields(string $collectionName): array
218218
$fields = [];
219219

220220
foreach ($this->reflectProperties($class) as $name => $prop) {
221-
if ($prop->getAttributes(NotPersistable::class) || isset($relations[$name])) {
221+
if ($prop->isVirtual() || $prop->getAttributes(NotPersistable::class) || isset($relations[$name])) {
222222
continue;
223223
}
224224

src/Hydrators/Base.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use DomainException;
88
use Respect\Data\Collections\Collection;
9-
use Respect\Data\Collections\Typed;
109
use Respect\Data\EntityFactory;
1110
use Respect\Data\Hydrator;
1211
use SplObjectStorage;
@@ -75,20 +74,4 @@ protected function wireRelationships(SplObjectStorage $entities): void
7574
}
7675
}
7776
}
78-
79-
/**
80-
* @param object|array<mixed, mixed> $row
81-
*
82-
* @return class-string
83-
*/
84-
protected function resolveEntityClass(
85-
Collection $collection,
86-
object|array $row,
87-
): string {
88-
if ($collection instanceof Typed) {
89-
return $collection->resolveEntityClass($this->entityFactory, $row);
90-
}
91-
92-
return $this->entityFactory->resolveClass((string) $collection->name);
93-
}
9477
}

src/Hydrators/Nested.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private function hydrateNode(
4343
SplObjectStorage $entities,
4444
): void {
4545
$entity = $this->entityFactory->create(
46-
$this->resolveEntityClass($collection, $data),
46+
$this->entityFactory->resolveClass((string) $collection->name),
4747
);
4848

4949
foreach ($data as $key => $value) {

src/Hydrators/PrestyledAssoc.php

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
use DomainException;
88
use Respect\Data\CollectionIterator;
99
use Respect\Data\Collections\Collection;
10-
use Respect\Data\Collections\Composite;
1110
use SplObjectStorage;
1211

13-
use function array_keys;
1412
use function explode;
1513
use function is_array;
1614

@@ -52,11 +50,15 @@ public function hydrateAll(
5250
$instances = [];
5351

5452
foreach ($grouped as $prefix => $props) {
55-
$basePrefix = $this->resolveCompositionBase($prefix, $collMap);
53+
if (!isset($collMap[$prefix])) {
54+
throw new DomainException('Unknown column prefix "' . $prefix . '" in hydration row');
55+
}
56+
57+
$basePrefix = $prefix;
5658

5759
if (!isset($instances[$basePrefix])) {
5860
$coll = $collMap[$basePrefix];
59-
$class = $this->resolveEntityClass($coll, $props);
61+
$class = $this->entityFactory->resolveClass((string) $coll->name);
6062
$instances[$basePrefix] = $this->entityFactory->create($class);
6163
$entities[$instances[$basePrefix]] = $coll;
6264
}
@@ -83,45 +85,11 @@ private function buildCollMap(Collection $collection): array
8385

8486
$this->collMap = [];
8587
foreach (CollectionIterator::recursive($collection) as $spec => $c) {
86-
if ($c->name === null) {
87-
continue;
88-
}
89-
9088
$this->collMap[$spec] = $c;
9189
}
9290

9391
$this->cachedCollection = $collection;
9492

9593
return $this->collMap;
9694
}
97-
98-
/**
99-
* Resolve a composition prefix back to its base entity specifier.
100-
*
101-
* Composition columns use prefixes like "post_WITH_comment" (see Composite::COMPOSITION_MARKER).
102-
* This returns "post" so properties are merged into the parent entity.
103-
*
104-
* @param array<string, Collection> $collMap
105-
*/
106-
private function resolveCompositionBase(string $prefix, array $collMap): string
107-
{
108-
if (isset($collMap[$prefix])) {
109-
return $prefix;
110-
}
111-
112-
// Look for a base specifier where this prefix is a composition alias
113-
foreach ($collMap as $spec => $coll) {
114-
if (!$coll instanceof Composite) {
115-
continue;
116-
}
117-
118-
foreach (array_keys($coll->compositions) as $compName) {
119-
if ($prefix === $spec . Composite::COMPOSITION_MARKER . $compName) {
120-
return $spec;
121-
}
122-
}
123-
}
124-
125-
throw new DomainException('Unknown column prefix "' . $prefix . '" in hydration row');
126-
}
12795
}

tests/AbstractMapperTest.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPUnit\Framework\TestCase;
1010
use ReflectionObject;
1111
use Respect\Data\Collections\Collection;
12-
use Respect\Data\Collections\Composite;
1312
use Respect\Data\Hydrators\Nested;
1413
use Respect\Data\Styles\CakePHP;
1514
use Respect\Data\Styles\Standard;
@@ -52,20 +51,6 @@ public function registerCollectionShouldAddCollectionToPool(): void
5251
$this->assertEquals($coll->name, $clone->name);
5352
}
5453

55-
#[Test]
56-
public function callingRegisteredCollectionWithArgsDerives(): void
57-
{
58-
$coll = Composite::post(['comment' => ['text']]);
59-
$this->mapper->registerCollection('postComment', $coll);
60-
61-
$derived = $this->mapper->postComment(filter: 5);
62-
63-
$this->assertInstanceOf(Composite::class, $derived);
64-
$this->assertEquals('post', $derived->name);
65-
$this->assertEquals(['comment' => ['text']], $derived->compositions);
66-
$this->assertEquals(5, $derived->filter);
67-
}
68-
6954
#[Test]
7055
public function callingRegisteredCollectionWithoutArgsClones(): void
7156
{
@@ -1305,4 +1290,14 @@ public function mergeWithIdentityMapNormalizesConditionFallback(): void
13051290
$this->assertTrue($mapper->isTracked($merged));
13061291
$this->assertFalse($mapper->isTracked($fetched));
13071292
}
1293+
1294+
#[Test]
1295+
public function callingRegisteredCollectionWithArgsDerives(): void
1296+
{
1297+
$coll = Collection::post();
1298+
$this->mapper->registerCollection('post', $coll);
1299+
$derived = $this->mapper->post(filter: 5);
1300+
$this->assertEquals('post', $derived->name);
1301+
$this->assertEquals(5, $derived->filter);
1302+
}
13081303
}

tests/Collections/CompositeTest.php

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)