Skip to content
Closed
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
31 changes: 30 additions & 1 deletion src/AbstractQueryDataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@

/** @var array|object $row */
foreach ($iterator as $index => $row) {
$this->reachRow($row);
yield $index => $this->createItem($row);
}
}
Expand All @@ -89,16 +90,16 @@
if ($this->count === null) {
$q = $this->countParam ?? '*';

if ($q === '*' && is_array($this->data) && !$this->limit && !$this->offset) {

Check warning on line 93 in src/AbstractQueryDataReader.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "LogicalNot": @@ @@ { if ($this->count === null) { $q = $this->countParam ?? '*'; - if ($q === '*' && is_array($this->data) && !$this->limit && !$this->offset) { + if ($q === '*' && is_array($this->data) && !$this->limit && $this->offset) { $this->count = count($this->data); } else { $query = $this->getPreparedQuery();

Check warning on line 93 in src/AbstractQueryDataReader.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "LogicalNot": @@ @@ { if ($this->count === null) { $q = $this->countParam ?? '*'; - if ($q === '*' && is_array($this->data) && !$this->limit && !$this->offset) { + if ($q === '*' && is_array($this->data) && $this->limit && !$this->offset) { $this->count = count($this->data); } else { $query = $this->getPreparedQuery();

Check warning on line 93 in src/AbstractQueryDataReader.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "Identical": @@ @@ { if ($this->count === null) { $q = $this->countParam ?? '*'; - if ($q === '*' && is_array($this->data) && !$this->limit && !$this->offset) { + if ($q !== '*' && is_array($this->data) && !$this->limit && !$this->offset) { $this->count = count($this->data); } else { $query = $this->getPreparedQuery();
$this->count = count($this->data);
} else {
$query = $this->getPreparedQuery();
$query->offset(null);

Check warning on line 97 in src/AbstractQueryDataReader.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ $this->count = count($this->data); } else { $query = $this->getPreparedQuery(); - $query->offset(null); + $query->limit(null); $query->orderBy(''); /** @psalm-var non-negative-int */
$query->limit(null);

Check warning on line 98 in src/AbstractQueryDataReader.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ } else { $query = $this->getPreparedQuery(); $query->offset(null); - $query->limit(null); + $query->orderBy(''); /** @psalm-var non-negative-int */ $this->count = (int) $query->count($q);
$query->orderBy('');

Check warning on line 99 in src/AbstractQueryDataReader.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ $query = $this->getPreparedQuery(); $query->offset(null); $query->limit(null); - $query->orderBy(''); + /** @psalm-var non-negative-int */ $this->count = (int) $query->count($q); }

/** @psalm-var non-negative-int */
$this->count = (int) $query->count($q);

Check warning on line 102 in src/AbstractQueryDataReader.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "CastInt": @@ @@ $query->limit(null); $query->orderBy(''); /** @psalm-var non-negative-int */ - $this->count = (int) $query->count($q); + $this->count = $query->count($q); } } return $this->count;
}
}

Expand All @@ -107,15 +108,15 @@

public function getPreparedQuery(): QueryInterface
{
$query = $this->applyFilter(clone $this->query);

Check warning on line 111 in src/AbstractQueryDataReader.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "CloneRemoval": @@ @@ } public function getPreparedQuery(): QueryInterface { - $query = $this->applyFilter(clone $this->query); + $query = $this->applyFilter($this->query); $query = $this->applyHaving($query); if ($this->limit) { $query->limit($this->limit);
$query = $this->applyHaving($query);

if ($this->limit) {
$query->limit($this->limit);

Check warning on line 115 in src/AbstractQueryDataReader.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ $query = $this->applyFilter(clone $this->query); $query = $this->applyHaving($query); if ($this->limit) { - $query->limit($this->limit); + } if ($this->offset) { $query->offset($this->offset);
}

if ($this->offset) {
$query->offset($this->offset);

Check warning on line 119 in src/AbstractQueryDataReader.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ $query->limit($this->limit); } if ($this->offset) { - $query->offset($this->offset); + } if ($criteria = $this->sort?->getCriteria()) { $query->addOrderBy($criteria);
}

if ($criteria = $this->sort?->getCriteria()) {
Expand Down Expand Up @@ -282,11 +283,15 @@
{
if ($this->data === null) {
$this->data = [];

$rows = $this->getPreparedQuery()->all();
$this->reachRows($rows);

/**
* @psalm-var TKey $key
* @psalm-var array $row
*/
foreach ($this->getPreparedQuery()->all() as $key => $row) {
foreach ($rows as $key => $row) {
$this->data[$key] = $this->createItem($row);
}
}
Expand Down Expand Up @@ -317,6 +322,30 @@
*/
abstract protected function createItem(array|object $row): array|object;

/**
* This method is called before processing the query results ({@see read()}).
*
* It allows modifying the array of rows before passing them to the {@see createItem()} method.
*
* @param array $rows An array of query result rows.
*
* @psalm-param array<array|object> $rows
*/
protected function reachRows(array &$rows): void
{
}

/**
* This method is called before processing each individual row of the query result ({@see getIterator()}).
*
* It allows modifying the row before passing it to the {@see createItem()} method.
*
* @param array|object $row A single row from the query result.
*/
protected function reachRow(array|object &$row): void
{
}

public function getFilter(): ?FilterInterface
{
return $this->filter;
Expand Down