Skip to content

Commit

Permalink
Merge pull request #478: better types in Select class
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored May 9, 2024
2 parents 107de86 + 50193b8 commit 892c275
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
php-version: ${{ matrix.php-version }}
coverage: pcov
tools: pecl
extensions: mbstring, pdo, pdo_sqlite, pdo_pgsql, pdo_sqlsrv-5.11.1, pdo_mysql
extensions: mbstring, pdo, pdo_sqlite, pdo_pgsql, pdo_sqlsrv, pdo_mysql
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
Expand Down
29 changes: 15 additions & 14 deletions src/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* @method mixed max($identifier) Perform aggregation (MAX) based on column or expression value.
* @method mixed sum($identifier) Perform aggregation (SUM) based on column or expression value.
*
* @template TEntity of object
* @template-covariant TEntity of object
*/
class Select implements IteratorAggregate, Countable, PaginableInterface
{
Expand Down Expand Up @@ -130,7 +130,7 @@ public function __clone()
/**
* Create new Selector with applied scope. By default no scope used.
*
* @return Select<TEntity>
* @return static<TEntity>
*/
public function scope(ScopeInterface $scope = null): self
{
Expand Down Expand Up @@ -160,7 +160,7 @@ public function buildQuery(): SelectQuery
*
* @psalm-param string|int|list<string|int>|object ...$ids
*
* @return Select<TEntity>
* @return static<TEntity>
*/
public function wherePK(string|int|array|object ...$ids): self
{
Expand Down Expand Up @@ -195,7 +195,7 @@ public function count(string $column = null): int
}

/**
* @return Select<TEntity>
* @return static<TEntity>
*/
public function limit(int $limit): self
{
Expand All @@ -205,7 +205,7 @@ public function limit(int $limit): self
}

/**
* @return Select<TEntity>
* @return static<TEntity>
*/
public function offset(int $offset): self
{
Expand Down Expand Up @@ -267,7 +267,7 @@ public function offset(int $offset): self
*
* @see with()
*
* @return Select<TEntity>
* @return static<TEntity>
*/
public function load(string|array $relation, array $options = []): self
{
Expand Down Expand Up @@ -357,7 +357,7 @@ public function load(string|array $relation, array $options = []): self
*
* @see load()
*
* @return Select<TEntity>
* @return static<TEntity>
*/
public function with(string|array $relation, array $options = []): self
{
Expand Down Expand Up @@ -396,16 +396,16 @@ public function fetchOne(array $query = null): ?object
return null;
}

/** @var TEntity */
/** @var TEntity $result */
return $this->entityFactory->make($this->loader->getTarget(), $data[0], Node::MANAGED, typecast: true);
}

/**
* Fetch all records in a form of array.
*
* @return array<int, TEntity>
* @return list<TEntity>
*/
public function fetchAll(): array
public function fetchAll(): iterable
{
return \iterator_to_array($this->getIterator(), false);
}
Expand Down Expand Up @@ -434,17 +434,18 @@ public function getIterator(bool $findInHeap = false): Iterator
*
* @return array<array-key, array<string, mixed>>
*/
public function fetchData(bool $typecast = true): array
public function fetchData(bool $typecast = true): iterable
{
$node = $this->loader->createNode();
$this->loader->loadData($node, false);

if (!$typecast) {
return $node->getResult();
}

$mapper = $this->mapperProvider->getMapper($this->loader->getTarget());

return array_map([$mapper, 'cast'], $node->getResult());
return \array_map([$mapper, 'cast'], $node->getResult());
}

/**
Expand All @@ -465,7 +466,7 @@ public function loadSubclasses(bool $load = true): self
* @param list<non-empty-string> $pk
* @param list<array|int|object|string> $args
*
* @return Select<TEntity>
* @return static<TEntity>
*/
private function buildCompositePKQuery(array $pk, array $args): self
{
Expand All @@ -481,7 +482,7 @@ private function buildCompositePKQuery(array $pk, array $args): self
);
}

$isAssoc = !array_is_list($values);
$isAssoc = !\array_is_list($values);
foreach ($values as $key => $value) {
if ($isAssoc && !\in_array($key, $pk, true)) {
throw new InvalidArgumentException(\sprintf('Primary key `%s` not found.', $key));
Expand Down
2 changes: 1 addition & 1 deletion tests/ORM/Functional/Driver/Common/Typecast/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function testTypecastWithJti(): void
}

/**
* @covers CompositeTypecast::cast()
* @see CompositeTypecast::cast()
*/
public function testUseCompositeTypecast(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
ACCEPT_EULA: "Y"

cycle-mysql_latest:
image: mysql:latest
image: mysql:8.0.37
restart: always
command: --default-authentication-plugin=mysql_native_password
ports:
Expand Down

0 comments on commit 892c275

Please sign in to comment.