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
3 changes: 0 additions & 3 deletions src/Hydrators/FlatNum.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@

use PDOStatement;
use Respect\Data\Hydrators\Flat;
use Respect\Data\Styles\Stylable;

/** Resolves column names from PDOStatement column metadata for numeric-indexed rows */
final class FlatNum extends Flat
{
public function __construct(
private readonly PDOStatement $statement,
Stylable $style,
) {
parent::__construct($style);
}

protected function resolveColumnName(mixed $reference, mixed $raw): string
Expand Down
13 changes: 2 additions & 11 deletions src/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function flush(): void

protected function defaultHydrator(Collection $collection): Hydrator
{
return new FlatNum($this->lastStatement, $this->style);
return new FlatNum($this->lastStatement);
}

private function flushSingle(object $entity): void
Expand Down Expand Up @@ -460,17 +460,8 @@ private function fetchHydrated(Collection $collection, PDOStatement $statement):
$this->lastStatement = $statement;
$hydrator = $this->resolveHydrator($collection);
$row = $statement->fetch(PDO::FETCH_NUM);
$entities = $hydrator->hydrate($row, $collection, $this->entityFactory);

if ($entities === false) {
return false;
}

if ($entities->count() > 1) {
$this->postHydrate($entities);
}

return $entities;
return $hydrator->hydrate($row, $collection, $this->entityFactory);
}

private function createStatement(
Expand Down
9 changes: 4 additions & 5 deletions tests/Hydrators/FlatNumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Respect\Data\Collections\Collection;
use Respect\Data\Collections\Typed;
use Respect\Data\EntityFactory;
use Respect\Data\Styles\Standard;
use stdClass;

#[CoversClass(FlatNum::class)]
Expand Down Expand Up @@ -39,7 +38,7 @@ public function hydrateSingleEntityFromNumericRow(): void
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_NUM);

$hydrator = new FlatNum($stmt, new Standard());
$hydrator = new FlatNum($stmt);
$result = $hydrator->hydrate($row, Collection::author(), $this->factory);

$this->assertNotFalse($result);
Expand All @@ -60,7 +59,7 @@ public function hydrateMultipleEntitiesFromJoinedRow(): void
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_NUM);

$hydrator = new FlatNum($stmt, new Standard());
$hydrator = new FlatNum($stmt);
$collection = Collection::author()->post;
$result = $hydrator->hydrate($row, $collection, $this->factory);

Expand All @@ -75,7 +74,7 @@ public function hydrateReturnsFalseForEmptyResult(): void
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_NUM);

$hydrator = new FlatNum($stmt, new Standard());
$hydrator = new FlatNum($stmt);

$this->assertFalse($hydrator->hydrate($row, Collection::author(), $this->factory));
}
Expand All @@ -91,7 +90,7 @@ public function hydrateResolvesTypedEntity(): void
$row = $stmt->fetch(PDO::FETCH_NUM);

$factory = new EntityFactory(entityNamespace: 'Respect\Relational\Hydrators\\');
$hydrator = new FlatNum($stmt, new Standard());
$hydrator = new FlatNum($stmt);
$collection = Typed::by('type')->issue();
$result = $hydrator->hydrate($row, $collection, $factory);

Expand Down
Loading