From 30c76e7ee6026978da03bf3518bbff5868d7659c Mon Sep 17 00:00:00 2001 From: lotyp Date: Sat, 4 May 2024 21:14:40 +0300 Subject: [PATCH 1/7] fix: set generic template to be as covariant --- src/Select.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Select.php b/src/Select.php index 2d5b2ddd..aad61c58 100644 --- a/src/Select.php +++ b/src/Select.php @@ -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 { From 6218a49465524db6270266efcc13bdd9b688f4f1 Mon Sep 17 00:00:00 2001 From: lotyp Date: Wed, 8 May 2024 14:04:30 +0300 Subject: [PATCH 2/7] fix: psalm typings in Select class --- src/Select.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Select.php b/src/Select.php index aad61c58..7c98a325 100644 --- a/src/Select.php +++ b/src/Select.php @@ -130,7 +130,7 @@ public function __clone() /** * Create new Selector with applied scope. By default no scope used. * - * @return Select + * @return static */ public function scope(ScopeInterface $scope = null): self { @@ -160,7 +160,7 @@ public function buildQuery(): SelectQuery * * @psalm-param string|int|list|object ...$ids * - * @return Select + * @return static */ public function wherePK(string|int|array|object ...$ids): self { @@ -195,7 +195,7 @@ public function count(string $column = null): int } /** - * @return Select + * @return static */ public function limit(int $limit): self { @@ -205,7 +205,7 @@ public function limit(int $limit): self } /** - * @return Select + * @return static */ public function offset(int $offset): self { @@ -267,7 +267,7 @@ public function offset(int $offset): self * * @see with() * - * @return Select + * @return static */ public function load(string|array $relation, array $options = []): self { @@ -357,7 +357,7 @@ public function load(string|array $relation, array $options = []): self * * @see load() * - * @return Select + * @return static */ public function with(string|array $relation, array $options = []): self { @@ -465,7 +465,7 @@ public function loadSubclasses(bool $load = true): self * @param list $pk * @param list $args * - * @return Select + * @return static */ private function buildCompositePKQuery(array $pk, array $args): self { @@ -481,7 +481,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)); From 8bf2d4815c1bc69b7a13a3a2a90f64d6ba4747c9 Mon Sep 17 00:00:00 2001 From: lotyp Date: Wed, 8 May 2024 17:35:45 +0300 Subject: [PATCH 3/7] feat(select): return type expanded from array to iterable to increase flexibility --- src/Select.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Select.php b/src/Select.php index 7c98a325..af9fb801 100644 --- a/src/Select.php +++ b/src/Select.php @@ -396,16 +396,18 @@ public function fetchOne(array $query = null): ?object return null; } - /** @var TEntity */ - return $this->entityFactory->make($this->loader->getTarget(), $data[0], Node::MANAGED, typecast: true); + /** @var TEntity $result */ + $result = $this->entityFactory->make($this->loader->getTarget(), $data[0], Node::MANAGED, typecast: true); + + return $result; } /** * Fetch all records in a form of array. * - * @return array + * @return list */ - public function fetchAll(): array + public function fetchAll(): iterable { return \iterator_to_array($this->getIterator(), false); } @@ -434,7 +436,7 @@ public function getIterator(bool $findInHeap = false): Iterator * * @return array> */ - public function fetchData(bool $typecast = true): array + public function fetchData(bool $typecast = true): iterable { $node = $this->loader->createNode(); $this->loader->loadData($node, false); @@ -442,9 +444,10 @@ public function fetchData(bool $typecast = true): array 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()); } /** From 1596a329cada2b9cccf6e3e324d68e4ae432bfee Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 8 May 2024 14:36:18 +0000 Subject: [PATCH 4/7] Apply fixes from StyleCI --- src/Select.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Select.php b/src/Select.php index af9fb801..1f70af70 100644 --- a/src/Select.php +++ b/src/Select.php @@ -397,9 +397,7 @@ public function fetchOne(array $query = null): ?object } /** @var TEntity $result */ - $result = $this->entityFactory->make($this->loader->getTarget(), $data[0], Node::MANAGED, typecast: true); - - return $result; + return $this->entityFactory->make($this->loader->getTarget(), $data[0], Node::MANAGED, typecast: true); } /** From e416963a0f11eef4ca84b8ff5c3ecbf09af946a4 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 8 May 2024 19:21:17 +0400 Subject: [PATCH 5/7] Fix tests --- tests/ORM/Functional/Driver/Common/Typecast/SchemaTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ORM/Functional/Driver/Common/Typecast/SchemaTest.php b/tests/ORM/Functional/Driver/Common/Typecast/SchemaTest.php index 13768d24..7a5a6651 100644 --- a/tests/ORM/Functional/Driver/Common/Typecast/SchemaTest.php +++ b/tests/ORM/Functional/Driver/Common/Typecast/SchemaTest.php @@ -198,7 +198,7 @@ public function testTypecastWithJti(): void } /** - * @covers CompositeTypecast::cast() + * @see CompositeTypecast::cast() */ public function testUseCompositeTypecast(): void { From f186a65f1ba934620d7b182686ae2bbe54929251 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 8 May 2024 19:31:38 +0400 Subject: [PATCH 6/7] Fix pdo_sqlsrv version --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d08d6b36..2b21ad92 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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)" From 46b6bd7d10be660c5aeb695a85e1497c6cbf875f Mon Sep 17 00:00:00 2001 From: lotyp Date: Thu, 9 May 2024 13:26:12 +0300 Subject: [PATCH 7/7] ci: stick mysql container to fixed version --- tests/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 67d0b756..a51a8cca 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -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: