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
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 5
level: 7
paths:
- src/
- tests/
Expand Down
2 changes: 2 additions & 0 deletions src/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function getSql(): Sql
return $this->currentSql;
}

/** @param array<int, mixed>|null $extra */
public function prepare(string $queryString, mixed $object = '\stdClass', array|null $extra = null): PDOStatement
{
$statement = $this->connection->prepare($queryString);
Expand All @@ -72,6 +73,7 @@ public function prepare(string $queryString, mixed $object = '\stdClass', array|
return $statement;
}

/** @param array<int, mixed>|null $params */
public function query(string $rawSql, array|null $params = null): static
{
$this->currentSql->setQuery($rawSql, $params);
Expand Down
24 changes: 21 additions & 3 deletions src/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ protected function transformSingleRow(object $row, string $entityName): object
{
$newRow = $this->getNewEntityByName($entityName);

foreach ($row as $prop => $value) {
foreach (get_object_vars($row) as $prop => $value) {
$this->inferSet($newRow, $prop, $value);
}

Expand Down Expand Up @@ -557,7 +557,11 @@ protected function inferGet(object &$object, string $prop): mixed
}
}

/** @param array<int, mixed> $row */
/**
* @param array<int, mixed> $row
*
* @return SplObjectStorage<object, Collection>
*/
protected function createEntities(
array $row,
PDOStatement $statement,
Expand All @@ -573,6 +577,10 @@ protected function createEntities(
//Reversely traverses the columns to avoid conflicting foreign key names
foreach (array_reverse($row, true) as $col => $value) {
$columnMeta = $statement->getColumnMeta($col);
if ($columnMeta === false) {
continue;
}

$columnName = $columnMeta['name'];
$primaryName = $this->getStyle()->identifier(
$entities[$entityInstance]->getName(),
Expand All @@ -590,7 +598,11 @@ protected function createEntities(
return $entities;
}

/** @return array<int, object> */
/**
* @param SplObjectStorage<object, Collection> $entities
*
* @return array<int, object>
*/
protected function buildEntitiesInstances(
Collection $collection,
SplObjectStorage $entities,
Expand Down Expand Up @@ -620,6 +632,7 @@ protected function buildEntitiesInstances(
return $entitiesInstances;
}

/** @param SplObjectStorage<object, Collection> $entities */
protected function postHydrate(SplObjectStorage $entities): void
{
$entitiesClone = clone $entities;
Expand All @@ -639,6 +652,7 @@ protected function postHydrate(SplObjectStorage $entities): void
}
}

/** @param SplObjectStorage<object, Collection> $entities */
protected function tryHydration(SplObjectStorage $entities, object $sub, string $field, mixed &$v): void
{
$tableName = $entities[$sub]->getName();
Expand Down Expand Up @@ -678,6 +692,7 @@ protected function getAllProperties(object $object): array
return $cols;
}

/** @param SplObjectStorage<object, Collection> $hydrated */
private function parseHydrated(SplObjectStorage $hydrated): mixed
{
$this->tracked->addAll($hydrated);
Expand All @@ -686,6 +701,7 @@ private function parseHydrated(SplObjectStorage $hydrated): mixed
return $hydrated->current();
}

/** @return SplObjectStorage<object, Collection>|false */
private function fetchHydrated(Collection $collection, PDOStatement $statement): SplObjectStorage|false
{
if (!$collection->hasMore()) {
Expand All @@ -711,6 +727,7 @@ private function createStatement(
return $statement;
}

/** @return SplObjectStorage<object, Collection>|false */
private function fetchSingle(
Collection $collection,
PDOStatement $statement,
Expand All @@ -733,6 +750,7 @@ private function fetchSingle(
return $entities;
}

/** @return SplObjectStorage<object, Collection>|false */
private function fetchMulti(
Collection $collection,
PDOStatement $statement,
Expand Down
3 changes: 3 additions & 0 deletions src/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Sql
/** @var array<int, mixed> */
protected array $params = [];

/** @param array<int, mixed>|null $params */
public function __construct(string $rawSql = '', array|null $params = null)
{
$this->setQuery($rawSql, $params);
Expand All @@ -52,6 +53,7 @@ public function getParams(): array
return $this->params;
}

/** @param array<int, mixed>|null $params */
public function setQuery(string $rawSql, array|null $params = null): static
{
$this->query = $rawSql;
Expand All @@ -62,6 +64,7 @@ public function setQuery(string $rawSql, array|null $params = null): static
return $this;
}

/** @param array<int, mixed>|null $params */
public function appendQuery(mixed $sql, array|null $params = null): static
{
$this->query = trim($this->query) . ' ' . $sql;
Expand Down
Loading
Loading