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
9 changes: 4 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ parameters:
- src/
- tests/
ignoreErrors:
- message: '/Call to an undefined (static )?method Respect\\Data\\(AbstractMapper|InMemoryMapper|Collections\\(Collection|Filtered|Composite|Typed))::\w+\(\)\./'
- message: '/Access to an undefined property Respect\\Data\\(AbstractMapper|InMemoryMapper|Collections\\Collection)::\$\w+\./'
- message: '/Call to an undefined (static )?method Respect\\Data\\(AbstractMapper|InMemoryMapper|Collections\\(Collection|Composite|Typed))::\w+\(\)\./'
- message: '/Unsafe usage of new static\(\)\./'
-
message: '/Expression .+ on a separate line does not do anything\./'
path: tests/
-
message: '/Property .+ is never read, only written\./'
path: tests/Stubs/
-
message: '/(Cannot access property|Parameter #1 .+ expects object|Access to an undefined property object)/'
path: tests/
64 changes: 9 additions & 55 deletions src/AbstractMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
namespace Respect\Data;

use Respect\Data\Collections\Collection;
use Respect\Data\Collections\Filtered;
use SplObjectStorage;

use function array_flip;
use function array_intersect_key;
use function count;
use function ctype_digit;
use function is_int;
Expand Down Expand Up @@ -82,13 +79,6 @@ public function markTracked(object $entity, Collection $collection): bool

public function persist(object $object, Collection $onCollection): object
{
$connectsTo = $onCollection->connectsTo;
if ($onCollection instanceof Filtered && $connectsTo !== null) {
$this->persist($object, $connectsTo);

return $object;
}

if ($this->isTracked($object)) {
$currentOp = $this->pending[$object] ?? null;
if ($currentOp !== 'insert') {
Expand Down Expand Up @@ -128,31 +118,9 @@ public function isTracked(object $entity): bool

public function registerCollection(string $alias, Collection $collection): void
{
$collection->bindMapper($this);
$this->collections[$alias] = $collection;
}

/**
* @param array<string, mixed> $columns
*
* @return array<string, mixed>
*/
protected function filterColumns(array $columns, Collection $collection): array
{
if (
!$collection instanceof Filtered
|| !$collection->filters
|| $collection->identifierOnly
|| $collection->name === null
) {
return $columns;
}

$id = $this->style->identifier($collection->name);

return array_intersect_key($columns, array_flip([...$collection->filters, $id]));
}

protected function registerInIdentityMap(object $entity, Collection $coll): void
{
if ($coll->name === null) {
Expand Down Expand Up @@ -183,11 +151,11 @@ protected function evictFromIdentityMap(object $entity, Collection $coll): void

protected function findInIdentityMap(Collection $collection): object|null
{
if ($collection->name === null || !is_scalar($collection->condition) || $collection->hasMore) {
if ($collection->name === null || !is_scalar($collection->filter) || $collection->hasChildren) {
return null;
}

$condition = $this->normalizeIdValue($collection->condition);
$condition = $this->normalizeIdValue($collection->filter);
if ($condition === null) {
return null;
}
Expand All @@ -202,7 +170,7 @@ private function tryMergeWithIdentityMap(object $entity, Collection $coll): obje
}

$entityId = $this->entityIdValue($entity, $coll->name);
$idValue = $entityId ?? $this->normalizeIdValue($coll->condition);
$idValue = $entityId ?? $this->normalizeIdValue($coll->filter);

if ($idValue === null) {
return null;
Expand Down Expand Up @@ -269,36 +237,22 @@ private function normalizeIdValue(mixed $value): int|string|null
return null;
}

public function __get(string $name): Collection
{
if (isset($this->collections[$name])) {
return $this->collections[$name];
}

$coll = new Collection($name);

return $coll->bindMapper($this);
}

public function __isset(string $alias): bool
{
return isset($this->collections[$alias]);
}

public function __set(string $alias, Collection $collection): void
{
$this->registerCollection($alias, $collection);
}

/** @param list<Collection|array<scalar, mixed>|scalar|null> $arguments */
/** @param list<mixed> $arguments */
public function __call(string $name, array $arguments): Collection
{
if (isset($this->collections[$name])) {
$collection = clone $this->collections[$name];
if (empty($arguments)) {
return clone $this->collections[$name];
}

return $collection->bindMapper($this)->with(...$arguments);
return $this->collections[$name]->derive(...$arguments); // @phpstan-ignore argument.type
}

return Collection::__callstatic($name, $arguments)->bindMapper($this);
return new Collection($name, ...$arguments); // @phpstan-ignore argument.type
}
}
10 changes: 2 additions & 8 deletions src/CollectionIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,13 @@ public function key(): string

public function hasChildren(): bool
{
return $this->current()->hasMore;
return $this->current()->hasChildren;
}

public function getChildren(): RecursiveArrayIterator
{
$c = $this->current();
$pool = $c->hasChildren ? $c->children : [];
if ($c->connectsTo !== null) {
$pool[] = $c->connectsTo;
}

return new static(
array_filter($pool, static fn(Collection $c): bool => $c->name !== null),
array_filter($this->current()->with, static fn(Collection $c): bool => $c->name !== null),
$this->namesCounts,
);
}
Expand Down
18 changes: 0 additions & 18 deletions src/CollectionNotBound.php

This file was deleted.

Loading
Loading