From a836ba4c60997ae8ca5d391a03904386b27288d6 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 30 Apr 2024 15:43:20 +0700 Subject: [PATCH 01/29] First attempt --- src/ActiveQuery.php | 55 +++++++++++----------------------------- src/ActiveQueryTrait.php | 22 ++++++---------- 2 files changed, 23 insertions(+), 54 deletions(-) diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php index 23ea9ea53..c81c426ca 100644 --- a/src/ActiveQuery.php +++ b/src/ActiveQuery.php @@ -16,6 +16,7 @@ use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Helper\DbArrayHelper; use Yiisoft\Db\Query\BatchQueryResultInterface; +use Yiisoft\Db\Query\Data\DataReaderInterface; use Yiisoft\Db\Query\Query; use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; @@ -148,11 +149,13 @@ public function batch(int $batchSize = 100): BatchQueryResultInterface ); } - public function each(int $batchSize = 100): BatchQueryResultInterface + public function each(): DataReaderInterface { - return parent::each($batchSize)->setPopulatedMethod( - fn (array $rows, null|Closure|string $indexBy) => $this->populate($rows, $indexBy) - ); + if ($this->getCallback() === null) { + $this->setCallback(fn (array $row) => $this->populate($row)); + } + + return parent::each(); } /** @@ -246,21 +249,13 @@ public function prepare(QueryBuilderInterface $builder): QueryInterface * @throws ReflectionException * @throws Throwable */ - public function populate(array $rows, Closure|string|null $indexBy = null): array + public function populate(array $row): array|object { - if (empty($rows)) { - return []; - } + // if (!empty($this->join) && $this->getIndexBy() === null) { + // $models = $this->removeDuplicatedModels($models); + // } - $models = $this->createModels($rows); - - if (empty($models)) { - return []; - } - - if (!empty($this->join) && $this->getIndexBy() === null) { - $models = $this->removeDuplicatedModels($models); - } + $models = [$this->createModel($row)]; if (!empty($this->with)) { $this->findWith($this->with, $models); @@ -270,7 +265,7 @@ public function populate(array $rows, Closure|string|null $indexBy = null): arra $this->addInverseRelations($models); } - return DbArrayHelper::populate($models, $indexBy); + return reset($models); } /** @@ -339,25 +334,6 @@ private function removeDuplicatedModels(array $models): array return array_values($models); } - /** - * @throws Exception - * @throws InvalidArgumentException - * @throws InvalidConfigException - * @throws NotSupportedException - * @throws ReflectionException - * @throws Throwable - */ - public function allPopulate(): array - { - $rows = $this->all(); - - if ($rows !== []) { - $rows = $this->populate($rows, $this->indexBy); - } - - return $rows; - } - /** * @throws Exception * @throws InvalidArgumentException @@ -371,11 +347,10 @@ public function onePopulate(): array|ActiveRecordInterface|null $row = $this->one(); if ($row !== null) { - $activeRecord = $this->populate([$row], $this->indexBy); - $row = reset($activeRecord) ?: null; + return $this->populate($row); } - return $row; + return null; } /** diff --git a/src/ActiveQueryTrait.php b/src/ActiveQueryTrait.php index e7dd8ed69..1cd2002c5 100644 --- a/src/ActiveQueryTrait.php +++ b/src/ActiveQueryTrait.php @@ -105,27 +105,21 @@ public function with(array|string ...$with): static * * @throws InvalidConfigException */ - protected function createModels(array $rows): array|null + protected function createModel(array $row): array { if ($this->asArray) { - return $rows; + return $row; } - $arClassInstance = []; + $arClass = $this->getARInstance(); - foreach ($rows as $row) { - $arClass = $this->getARInstance(); - - if (method_exists($arClass, 'instantiate')) { - $arClass = $arClass->instantiate($row); - } - - $arClass->populateRecord($row); - - $arClassInstance[] = $arClass; + if (method_exists($arClass, 'instantiate')) { + $arClass = $arClass->instantiate($row); } - return $arClassInstance; + $arClass->populateRecord($row); + + return $arClass; } /** From d01931ce08561254b16a608bbd87f6a675bd8467 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 13 Apr 2025 10:12:08 +0700 Subject: [PATCH 02/29] Improve --- src/ActiveQuery.php | 127 ++++++++--------------- src/ActiveQueryInterface.php | 4 +- src/ActiveQueryTrait.php | 19 ++-- tests/ActiveRecordTest.php | 3 +- tests/BatchQueryResultTest.php | 8 +- tests/MagicActiveRecordTest.php | 3 +- tests/Stubs/ActiveRecord/Animal.php | 7 -- tests/Stubs/MagicActiveRecord/Animal.php | 7 -- tests/Support/ModelFactory.php | 24 +++++ 9 files changed, 85 insertions(+), 117 deletions(-) create mode 100644 tests/Support/ModelFactory.php diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php index aa90daec1..aaac67377 100644 --- a/src/ActiveQuery.php +++ b/src/ActiveQuery.php @@ -14,8 +14,7 @@ use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Helper\DbArrayHelper; -use Yiisoft\Db\Query\BatchQueryResultInterface; -use Yiisoft\Db\Query\Data\DataReaderInterface; +use Yiisoft\Db\Query\DataReaderInterface; use Yiisoft\Db\Query\Query; use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; @@ -126,27 +125,12 @@ final public function __construct( parent::__construct($this->getARInstance()->db()); } - public function all(): array - { - if ($this->shouldEmulateExecution()) { - return []; - } - - return $this->populate($this->createCommand()->queryAll(), $this->indexBy); - } - - public function batch(int $batchSize = 100): BatchQueryResultInterface - { - return parent::batch($batchSize)->setPopulatedMethod($this->populate(...)); - } - public function each(): DataReaderInterface { - if ($this->getCallback() === null) { - $this->setCallback(fn (array $row) => $this->populate($row)); - } - - return parent::each(); + return $this->createCommand() + ->query() + ->indexBy($this->indexBy) + ->resultCallback($this->populate(...)); } /** @@ -241,21 +225,17 @@ public function prepare(QueryBuilderInterface $builder): QueryInterface * @throws ReflectionException * @throws Throwable */ - public function populate(array $rows, Closure|string|null $indexBy = null): array + public function populate(array $rows): array { if (empty($rows)) { return []; } - $models = $this->createModels($rows); - - if (empty($models)) { - return []; + if (!empty($this->join) && $this->indexBy === null) { + $rows = $this->removeDuplicatedRows($rows); } - if (!empty($this->join) && $this->getIndexBy() === null) { - $models = $this->removeDuplicatedModels($models); - } + $models = $this->createModels($rows); if (!empty($this->with)) { $this->findWith($this->with, $models); @@ -265,88 +245,58 @@ public function populate(array $rows, Closure|string|null $indexBy = null): arra $this->addInverseRelations($models); } - return ArArrayHelper::index($models, $indexBy); + return $models; } /** - * Removes duplicated models by checking their primary key values. + * Removes duplicated rows by checking their primary key values. * * This method is mainly called when a join query is performed, which may cause duplicated rows being returned. * - * @param ActiveRecordInterface[]|array[] $models The models to be checked. + * @param array[] $rows The rows to be checked. * * @throws CircularReferenceException * @throws Exception * @throws InvalidConfigException * @throws NotInstantiableException * - * @return ActiveRecordInterface[]|array[] The distinctive models. + * @return array[] The distinctive rows. */ - private function removeDuplicatedModels(array $models): array + private function removeDuplicatedRows(array $rows): array { - $model = reset($models); + $instance = $this->getARInstance(); + $pks = $instance->primaryKey(); - if ($this->asArray) { - $instance = $this->getARInstance(); - $pks = $instance->primaryKey(); + if (empty($pks)) { + throw new InvalidConfigException('Primary key of "' . $instance::class . '" can not be empty.'); + } - if (empty($pks)) { - throw new InvalidConfigException('Primary key of "' . $instance::class . '" can not be empty.'); - } - - foreach ($pks as $pk) { - /** @var array $model */ - if (!isset($model[$pk])) { - return $models; - } + foreach ($pks as $pk) { + if (!isset($rows[0][$pk])) { + return $rows; } + } - /** @var array[] $models */ - if (count($pks) === 1) { - $hash = array_column($models, reset($pks)); - } else { - $flippedPks = array_flip($pks); - $hash = array_map( - static fn (array $model): string => serialize(array_intersect_key($model, $flippedPks)), - $models - ); - } + if (count($pks) === 1) { + $hash = array_column($rows, reset($pks)); } else { - /** @var ActiveRecordInterface $model */ - $pks = $model->getPrimaryKey(true); - - if (empty($pks)) { - throw new InvalidConfigException('Primary key of "' . $model::class . '" can not be empty.'); - } - - /** @var ActiveRecordInterface[] $models */ - foreach ($pks as $pk) { - if ($pk === null) { - return $models; - } - } - - if (count($pks) === 1) { - $key = array_key_first($pks); - $hash = array_map( - static fn (ActiveRecordInterface $model): string => (string) $model->get($key), - $models - ); - } else { - $hash = array_map( - static fn (ActiveRecordInterface $model): string => serialize($model->getPrimaryKey(true)), - $models - ); - } + $flippedPks = array_flip($pks); + $hash = array_map( + static fn (array $row): string => serialize(array_intersect_key($row, $flippedPks)), + $rows + ); } - return array_values(array_combine($hash, $models)); + return array_values(array_combine($hash, $rows)); } public function one(): array|ActiveRecordInterface|null { - /** @var array|null $row */ - $row = parent::one(); + if ($this->shouldEmulateExecution()) { + return null; + } + + $row = $this->createCommand()->queryOne(); if ($row === null) { return null; @@ -960,6 +910,11 @@ public function getARInstance(): ActiveRecordInterface return new $class(); } + protected function index(array $rows): array + { + return ArArrayHelper::index($this->populate($rows), $this->indexBy); + } + private function createInstance(): static { return (new static($this->arClass)) diff --git a/src/ActiveQueryInterface.php b/src/ActiveQueryInterface.php index 094ee5156..f58a55990 100644 --- a/src/ActiveQueryInterface.php +++ b/src/ActiveQueryInterface.php @@ -351,11 +351,9 @@ public function sql(string|null $value): static; * * @param array[] $rows The raw query result from a database. * - * @psalm-param IndexKey|null $indexBy - * * @return ActiveRecordInterface[]|array[] The converted query result. */ - public function populate(array $rows, Closure|string|null $indexBy = null): array; + public function populate(array $rows): array; /** * Returns related record(s). diff --git a/src/ActiveQueryTrait.php b/src/ActiveQueryTrait.php index 32880b4b7..47d2a9429 100644 --- a/src/ActiveQueryTrait.php +++ b/src/ActiveQueryTrait.php @@ -114,21 +114,24 @@ protected function createModels(array $rows): array return $rows; } - $arClassInstance = []; + if ($this->resultCallback !== null) { + $rows = ($this->resultCallback)($rows); + } - foreach ($rows as $row) { - $arClass = $this->getARInstance(); + if ($rows[0] instanceof ActiveRecordInterface) { + return $rows; + } - if (method_exists($arClass, 'instantiate')) { - $arClass = $arClass->instantiate($row); - } + $models = []; + foreach ($rows as $row) { + $arClass = $this->getARInstance(); $arClass->populateRecord($row); - $arClassInstance[] = $arClass; + $models[] = $arClass; } - return $arClassInstance; + return $models; } /** diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index abcde13d2..7fce5a400 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -28,6 +28,7 @@ use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Profile; use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Type; use Yiisoft\ActiveRecord\Tests\Support\Assert; +use Yiisoft\ActiveRecord\Tests\Support\ModelFactory; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; use Yiisoft\Db\Exception\InvalidCallException; @@ -234,7 +235,7 @@ public function testPopulateRecordCallWhenQueryingOnParentClass(): void $dog = new Dog(); $dog->save(); - $animal = new ActiveQuery(Animal::class); + $animal = (new ActiveQuery(Animal::class))->resultCallback(ModelFactory::create(...)); $animals = $animal->where(['type' => Dog::class])->one(); $this->assertEquals('bark', $animals->getDoes()); diff --git a/tests/BatchQueryResultTest.php b/tests/BatchQueryResultTest.php index ca6d3a89e..038cc426f 100644 --- a/tests/BatchQueryResultTest.php +++ b/tests/BatchQueryResultTest.php @@ -50,8 +50,8 @@ public function testQuery(): void $this->assertCount(3, $allRows); - /** reset */ - $batch->reset(); + /** rewind */ + $batch->rewind(); /** empty query */ $query = $customerQuery->where(['id' => 100]); @@ -89,7 +89,7 @@ public function testQuery(): void $allRows = []; - foreach ($query->each(2) as $index => $row) { + foreach ($query->each() as $index => $row) { $allRows[$index] = $row; } $this->assertCount(3, $allRows); @@ -104,7 +104,7 @@ public function testQuery(): void $allRows = []; - foreach ($query->each(100) as $key => $row) { + foreach ($query->each() as $key => $row) { $allRows[$key] = $row; } diff --git a/tests/MagicActiveRecordTest.php b/tests/MagicActiveRecordTest.php index 4a6d09a63..b26ae38bc 100644 --- a/tests/MagicActiveRecordTest.php +++ b/tests/MagicActiveRecordTest.php @@ -23,6 +23,7 @@ use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\OrderItemWithNullFK; use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\Type; use Yiisoft\ActiveRecord\Tests\Support\Assert; +use Yiisoft\ActiveRecord\Tests\Support\ModelFactory; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; use Yiisoft\Db\Exception\InvalidCallException; @@ -227,7 +228,7 @@ public function testPopulateRecordCallWhenQueryingOnParentClass(): void $dog = new Dog(); $dog->save(); - $animal = new ActiveQuery(Animal::class); + $animal = (new ActiveQuery(Animal::class))->resultCallback(ModelFactory::create(...)); $animals = $animal->where(['type' => Dog::class])->one(); $this->assertEquals('bark', $animals->getDoes()); diff --git a/tests/Stubs/ActiveRecord/Animal.php b/tests/Stubs/ActiveRecord/Animal.php index 5530334b6..54ebd547d 100644 --- a/tests/Stubs/ActiveRecord/Animal.php +++ b/tests/Stubs/ActiveRecord/Animal.php @@ -32,13 +32,6 @@ public function getDoes() return $this->does; } - public function instantiate($row): ActiveRecordInterface - { - $class = $row['type']; - - return new $class(); - } - public function setDoes(string $value): void { $this->does = $value; diff --git a/tests/Stubs/MagicActiveRecord/Animal.php b/tests/Stubs/MagicActiveRecord/Animal.php index 2e2d0ae34..1dc269eaf 100644 --- a/tests/Stubs/MagicActiveRecord/Animal.php +++ b/tests/Stubs/MagicActiveRecord/Animal.php @@ -32,13 +32,6 @@ public function getDoes() return $this->does; } - public function instantiate($row): ActiveRecordInterface - { - $class = $row['type']; - - return new $class($this->db()); - } - public function setDoes(string $value): void { $this->does = $value; diff --git a/tests/Support/ModelFactory.php b/tests/Support/ModelFactory.php new file mode 100644 index 000000000..5e105d8ec --- /dev/null +++ b/tests/Support/ModelFactory.php @@ -0,0 +1,24 @@ +populateRecord($row); + + $models[] = $model; + } + + return $models; + } +} From 69962cff059aa0c2348520243a9ea205bd7a516b Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 13 Apr 2025 03:12:26 +0000 Subject: [PATCH 03/29] Apply fixes from StyleCI --- src/ActiveQuery.php | 1 - tests/Stubs/ActiveRecord/Animal.php | 1 - tests/Stubs/MagicActiveRecord/Animal.php | 1 - 3 files changed, 3 deletions(-) diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php index aaac67377..7dadc9aba 100644 --- a/src/ActiveQuery.php +++ b/src/ActiveQuery.php @@ -25,7 +25,6 @@ use function array_combine; use function array_flip; use function array_intersect_key; -use function array_key_first; use function array_map; use function array_merge; use function array_values; diff --git a/tests/Stubs/ActiveRecord/Animal.php b/tests/Stubs/ActiveRecord/Animal.php index 54ebd547d..b5e5e1e4a 100644 --- a/tests/Stubs/ActiveRecord/Animal.php +++ b/tests/Stubs/ActiveRecord/Animal.php @@ -5,7 +5,6 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord; use Yiisoft\ActiveRecord\ActiveRecord; -use Yiisoft\ActiveRecord\ActiveRecordInterface; /** * Class Animal. diff --git a/tests/Stubs/MagicActiveRecord/Animal.php b/tests/Stubs/MagicActiveRecord/Animal.php index 1dc269eaf..c6ad39fbc 100644 --- a/tests/Stubs/MagicActiveRecord/Animal.php +++ b/tests/Stubs/MagicActiveRecord/Animal.php @@ -5,7 +5,6 @@ namespace Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord; use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord; -use Yiisoft\ActiveRecord\ActiveRecordInterface; /** * Class Animal. From 7ba3e1ab9e543989dc6c84141fed0c31b53d9ba5 Mon Sep 17 00:00:00 2001 From: Tigrov <8563175+Tigrov@users.noreply.github.com> Date: Sun, 13 Apr 2025 03:16:18 +0000 Subject: [PATCH 04/29] Apply Rector changes (CI) --- src/ActiveQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php index 7dadc9aba..e329f07d8 100644 --- a/src/ActiveQuery.php +++ b/src/ActiveQuery.php @@ -124,7 +124,7 @@ final public function __construct( parent::__construct($this->getARInstance()->db()); } - public function each(): DataReaderInterface + public function each(int $batchSize = 100): DataReaderInterface { return $this->createCommand() ->query() From ca7127ecd055da1e8e3f659133140ab236c39707 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 13 Apr 2025 11:45:24 +0700 Subject: [PATCH 05/29] Fix psalm --- src/ActiveQuery.php | 14 +++++++++++++- src/ActiveQueryInterface.php | 10 ++++++++++ src/ActiveQueryTrait.php | 13 +++++++++---- src/ActiveRelationTrait.php | 26 ++++++++++++++------------ 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php index e329f07d8..194b558bb 100644 --- a/src/ActiveQuery.php +++ b/src/ActiveQuery.php @@ -103,7 +103,7 @@ * @psalm-import-type ARClass from ActiveQueryInterface * @psalm-import-type IndexKey from ArArrayHelper * - * @psalm-property IndexKey $indexBy + * @psalm-property IndexKey|null $indexBy * @psalm-suppress ClassMustBeFinal */ class ActiveQuery extends Query implements ActiveQueryInterface @@ -126,6 +126,7 @@ final public function __construct( public function each(int $batchSize = 100): DataReaderInterface { + /** @psalm-suppress InvalidArgument */ return $this->createCommand() ->query() ->indexBy($this->indexBy) @@ -223,6 +224,13 @@ public function prepare(QueryBuilderInterface $builder): QueryInterface * @throws NotSupportedException * @throws ReflectionException * @throws Throwable + * + * @psalm-param list $rows + * @psalm-return ( + * $rows is non-empty-list + * ? non-empty-list + * : list + * ) */ public function populate(array $rows): array { @@ -260,6 +268,9 @@ public function populate(array $rows): array * @throws NotInstantiableException * * @return array[] The distinctive rows. + * + * @psalm-param non-empty-list $rows + * @psalm-return non-empty-list */ private function removeDuplicatedRows(array $rows): array { @@ -286,6 +297,7 @@ private function removeDuplicatedRows(array $rows): array ); } + /** @psalm-var non-empty-list */ return array_values(array_combine($hash, $rows)); } diff --git a/src/ActiveQueryInterface.php b/src/ActiveQueryInterface.php index f58a55990..ff94adb1d 100644 --- a/src/ActiveQueryInterface.php +++ b/src/ActiveQueryInterface.php @@ -352,6 +352,13 @@ public function sql(string|null $value): static; * @param array[] $rows The raw query result from a database. * * @return ActiveRecordInterface[]|array[] The converted query result. + * + * @psalm-param list $rows + * @psalm-return ( + * $rows is non-empty-list + * ? non-empty-list + * : list + * ) */ public function populate(array $rows): array; @@ -638,6 +645,9 @@ public function one(): array|ActiveRecordInterface|null; * @throws InvalidArgumentException|InvalidConfigException|NotSupportedException|Throwable If {@see link()} is * invalid. * @return ActiveRecordInterface[]|array[] The related models. + * + * @psalm-param non-empty-list $primaryModels + * @psalm-param-out non-empty-list $primaryModels */ public function populateRelation(string $name, array &$primaryModels): array; } diff --git a/src/ActiveQueryTrait.php b/src/ActiveQueryTrait.php index 47d2a9429..bc2783b31 100644 --- a/src/ActiveQueryTrait.php +++ b/src/ActiveQueryTrait.php @@ -107,6 +107,9 @@ public function with(array|string ...$with): static * * @throws InvalidConfigException * @return ActiveRecordInterface[]|array[] The model instances. + * + * @psalm-param non-empty-list $rows + * @psalm-return non-empty-list */ protected function createModels(array $rows): array { @@ -116,10 +119,11 @@ protected function createModels(array $rows): array if ($this->resultCallback !== null) { $rows = ($this->resultCallback)($rows); - } - if ($rows[0] instanceof ActiveRecordInterface) { - return $rows; + if ($rows[0] instanceof ActiveRecordInterface) { + /** @psalm-var non-empty-list */ + return $rows; + } } $models = []; @@ -147,7 +151,8 @@ protected function createModels(array $rows): array * @throws ReflectionException * @throws Throwable * - * @param-out ActiveRecordInterface[]|array[] $models + * @psalm-param non-empty-list $models + * @psalm-param-out non-empty-list $models */ public function findWith(array $with, array &$models): void { diff --git a/src/ActiveRelationTrait.php b/src/ActiveRelationTrait.php index 65d9ee738..aab04161d 100644 --- a/src/ActiveRelationTrait.php +++ b/src/ActiveRelationTrait.php @@ -202,7 +202,8 @@ public function relatedRecords(): ActiveRecordInterface|array|null * * @throws InvalidConfigException * - * @param-out ActiveRecordInterface[]|array[] $result + * @psalm-param non-empty-list $result + * @psalm-param-out non-empty-list $result */ private function addInverseRelations(array &$result): void { @@ -232,9 +233,10 @@ private function addInverseRelations(array &$result): void } /** - * @return ActiveRecordInterface[]|array[] + * @psalm-param non-empty-list $primaryModels + * @psalm-param-out non-empty-list $primaryModels * - * @param-out ActiveRecordInterface[]|array[] $primaryModels + * @return ActiveRecordInterface[]|array[] */ public function populateRelation(string $name, array &$primaryModels): array { @@ -262,16 +264,16 @@ public function populateRelation(string $name, array &$primaryModels): array $models = [$this->one()]; $this->populateInverseRelation($models, $primaryModels); - $primaryModel = reset($primaryModels); + $primaryModel = $primaryModels[0]; if ($primaryModel instanceof ActiveRecordInterface) { $primaryModel->populateRelation($name, $models[0]); } else { /** - * @var array[] $primaryModels - * @psalm-suppress PossiblyNullArrayOffset + * @psalm-var non-empty-list $primaryModels + * @psalm-suppress UndefinedInterfaceMethod */ - $primaryModels[key($primaryModels)][$name] = $models[0]; + $primaryModels[0][$name] = $models[0]; } return $models; @@ -319,12 +321,14 @@ public function populateRelation(string $name, array &$primaryModels): array /** * @throws \Yiisoft\Definitions\Exception\InvalidConfigException + * + * @psalm-param non-empty-list $primaryModels */ private function populateInverseRelation( array &$models, array $primaryModels, ): void { - if ($this->inverseOf === null || empty($models) || empty($primaryModels)) { + if ($this->inverseOf === null || empty($models)) { return; } @@ -643,13 +647,11 @@ private function getModelKeys(ActiveRecordInterface|array $model, array $propert * @throws Throwable * @throws \Yiisoft\Definitions\Exception\InvalidConfigException * @return array[] + * + * @psalm-param non-empty-list $primaryModels */ private function findJunctionRows(array $primaryModels): array { - if (empty($primaryModels)) { - return []; - } - $this->filterByModels($primaryModels); /** @var array[] */ From 01769839a9d1d4b6c2c59e1b41bf10dcbd269a3c Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 13 Apr 2025 21:00:42 +0700 Subject: [PATCH 06/29] Install db on psalm --- .github/workflows/static.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index d92b0c00b..950024c43 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -22,9 +22,10 @@ concurrency: jobs: psalm: - uses: yiisoft/actions/.github/workflows/psalm.yml@master + uses: yiisoft/actions/.github/workflows/psalm.yml@install-subpackage with: os: >- ['ubuntu-latest'] php: >- ['8.1', '8.2', '8.3', '8.4'] + subpackage: db From 5d7009270f264203024c9179204c30d8b8030403 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 13 Apr 2025 21:19:31 +0700 Subject: [PATCH 07/29] Rerun tests --- .github/workflows/static.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 950024c43..ac5eda2e5 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -29,3 +29,4 @@ jobs: php: >- ['8.1', '8.2', '8.3', '8.4'] subpackage: db + From ac8729425c600ede237e02fa67aa2100864e6ab5 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 13 Apr 2025 21:32:46 +0700 Subject: [PATCH 08/29] Rerun tests --- .github/workflows/static.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index ac5eda2e5..950024c43 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -29,4 +29,3 @@ jobs: php: >- ['8.1', '8.2', '8.3', '8.4'] subpackage: db - From cf9be89b0d4d6136bb32eb9aa348aa683b5a70b7 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 13 Apr 2025 21:42:44 +0700 Subject: [PATCH 09/29] Rerun tests --- .github/workflows/static.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 950024c43..edc662ce0 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -28,4 +28,4 @@ jobs: ['ubuntu-latest'] php: >- ['8.1', '8.2', '8.3', '8.4'] - subpackage: db + subpackage: 'db' From 5a828700d1c82e437332821f94b09be60031ef0d Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 13 Apr 2025 21:47:53 +0700 Subject: [PATCH 10/29] Rerun tests --- .github/workflows/static.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index edc662ce0..950024c43 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -28,4 +28,4 @@ jobs: ['ubuntu-latest'] php: >- ['8.1', '8.2', '8.3', '8.4'] - subpackage: 'db' + subpackage: db From a78b5559e16ffad476e5190dbdcb3ceb7af22b18 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 13 Apr 2025 21:55:37 +0700 Subject: [PATCH 11/29] Fix tests --- .github/workflows/composer-require-checker.yml | 1 + .github/workflows/mutation.yml | 9 ++++++++- .github/workflows/rector.yml | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index 63a6ae994..806342311 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -28,3 +28,4 @@ jobs: ['ubuntu-latest'] php: >- ['8.1', '8.2', '8.3', '8.4'] + subpackage: db diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 749580626..2a643f204 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -61,8 +61,15 @@ jobs: - name: Update composer. run: composer self-update + - name: Install db. + uses: yiisoft/actions/install-subpackage@install-subpackage + with: + subpackage: db + - name: Install db-pgsql. - run: composer require yiisoft/db-pgsql --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + uses: yiisoft/actions/install-subpackage@install-subpackage + with: + subpackage: db-pgsql - name: Run infection. run: | diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index 4f2528500..3239bfe01 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -20,3 +20,4 @@ jobs: ['ubuntu-latest'] php: >- ['8.4'] + subpackage: db From e1ee83f533ad906c74c0480fee019c7f93b22f06 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 13 Apr 2025 21:58:51 +0700 Subject: [PATCH 12/29] Fix tests --- .github/workflows/composer-require-checker.yml | 2 +- .github/workflows/rector.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index 806342311..d58c1acc8 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -22,7 +22,7 @@ concurrency: jobs: composer-require-checker: - uses: yiisoft/actions/.github/workflows/composer-require-checker.yml@master + uses: yiisoft/actions/.github/workflows/composer-require-checker.yml@install-subpackage with: os: >- ['ubuntu-latest'] diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index 3239bfe01..8fe0e033a 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -14,7 +14,7 @@ concurrency: jobs: rector: - uses: yiisoft/actions/.github/workflows/rector.yml@master + uses: yiisoft/actions/.github/workflows/rector.yml@install-subpackage with: os: >- ['ubuntu-latest'] From 0026812973ccfa8201f8f10d46fbe00f87ae2dd6 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 13 Apr 2025 22:23:22 +0700 Subject: [PATCH 13/29] Update tests --- .github/workflows/db-mssql.yml | 19 ++++--------------- .github/workflows/db-mysql.yml | 19 ++++--------------- .github/workflows/db-oracle.yml | 19 ++++--------------- .github/workflows/db-pgsql.yml | 21 +++++---------------- .github/workflows/db-sqlite.yml | 26 ++++++-------------------- .github/workflows/mutation.yml | 2 +- 6 files changed, 24 insertions(+), 82 deletions(-) diff --git a/.github/workflows/db-mssql.yml b/.github/workflows/db-mssql.yml index 4c8cfc053..8d03fdbee 100644 --- a/.github/workflows/db-mssql.yml +++ b/.github/workflows/db-mssql.yml @@ -75,26 +75,15 @@ jobs: - name: Update composer. run: composer self-update - - name: Set environment variables pull request linux. - uses: yiisoft/actions/db/environment-linux@master - - name: Install db. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/install-subpackage@install-subpackage with: - BRANCH_NAME: ${{ env.BRANCH_NAME }} - COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} - CURRENT_PACKAGE: db - FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} - WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + subpackage: db - name: Install db-mssql. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/install-subpackage@install-subpackage with: - BRANCH_NAME: ${{ env.BRANCH_NAME }} - COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} - CURRENT_PACKAGE: db-mssql - FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} - WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + subpackage: db-mssql - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Mssql --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/db-mysql.yml b/.github/workflows/db-mysql.yml index 0266c79ae..0d3cca7de 100644 --- a/.github/workflows/db-mysql.yml +++ b/.github/workflows/db-mysql.yml @@ -67,26 +67,15 @@ jobs: - name: Update composer. run: composer self-update - - name: Set environment variables pull request linux. - uses: yiisoft/actions/db/environment-linux@master - - name: Install db. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/install-subpackage@install-subpackage with: - BRANCH_NAME: ${{ env.BRANCH_NAME }} - COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} - CURRENT_PACKAGE: db - FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} - WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + subpackage: db - name: Install db-mysql. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/install-subpackage@install-subpackage with: - BRANCH_NAME: ${{ env.BRANCH_NAME }} - COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} - CURRENT_PACKAGE: db-mysql - FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} - WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + subpackage: db-mysql - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Mysql --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/db-oracle.yml b/.github/workflows/db-oracle.yml index 6eb16852b..74a97bcf1 100644 --- a/.github/workflows/db-oracle.yml +++ b/.github/workflows/db-oracle.yml @@ -73,26 +73,15 @@ jobs: - name: Update composer. run: composer self-update - - name: Set environment variables pull request linux. - uses: yiisoft/actions/db/environment-linux@master - - name: Install db. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/install-subpackage@install-subpackage with: - BRANCH_NAME: ${{ env.BRANCH_NAME }} - COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} - CURRENT_PACKAGE: db - FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} - WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + subpackage: db - name: Install db-oracle. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/install-subpackage@install-subpackage with: - BRANCH_NAME: ${{ env.BRANCH_NAME }} - COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} - CURRENT_PACKAGE: db-oracle - FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} - WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + subpackage: db-oracle - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Oracle --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/db-pgsql.yml b/.github/workflows/db-pgsql.yml index 3dc4ace5f..91adc5fc9 100644 --- a/.github/workflows/db-pgsql.yml +++ b/.github/workflows/db-pgsql.yml @@ -43,7 +43,7 @@ jobs: services: postgres: - image: postgres:16 + image: postgres:17 env: POSTGRES_USER: root POSTGRES_PASSWORD: root @@ -67,26 +67,15 @@ jobs: - name: Update composer. run: composer self-update - - name: Set environment variables pull request linux. - uses: yiisoft/actions/db/environment-linux@master - - name: Install db. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/install-subpackage@install-subpackage with: - BRANCH_NAME: ${{ env.BRANCH_NAME }} - COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} - CURRENT_PACKAGE: db - FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} - WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + subpackage: db - name: Install db-pgsql. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/install-subpackage@install-subpackage with: - BRANCH_NAME: ${{ env.BRANCH_NAME }} - COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} - CURRENT_PACKAGE: db-pgsql - FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} - WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + subpackage: db-pgsql - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Pgsql --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/db-sqlite.yml b/.github/workflows/db-sqlite.yml index 8d1ce8f02..58f55dc35 100644 --- a/.github/workflows/db-sqlite.yml +++ b/.github/workflows/db-sqlite.yml @@ -60,31 +60,17 @@ jobs: - name: Update composer. run: composer self-update - - name: Set environment variables pull request linux. - if: matrix.os == 'ubuntu-latest' - uses: yiisoft/actions/db/environment-linux@master - - - name: Set environment variables pull request windows. - if: matrix.os == 'windows-latest' - uses: yiisoft/actions/db/environment-windows@master - - name: Install db. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/install-subpackage@install-subpackage with: - BRANCH_NAME: ${{ env.BRANCH_NAME }} - COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} - CURRENT_PACKAGE: db - FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} - WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + subpackage: db + os: ${{ matrix.os }} - name: Install db-sqlite. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/install-subpackage@install-subpackage with: - BRANCH_NAME: ${{ env.BRANCH_NAME }} - COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} - CURRENT_PACKAGE: db-sqlite - FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} - WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + subpackage: db-sqlite + os: ${{ matrix.os }} - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Sqlite --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 2a643f204..e20a4756c 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -37,7 +37,7 @@ jobs: services: postgres: - image: postgres:16 + image: postgres:17 env: POSTGRES_USER: root POSTGRES_PASSWORD: root From 527502350740f90db4db69e029141db2d2b795e0 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 13 Apr 2025 22:37:27 +0700 Subject: [PATCH 14/29] Update tests --- .github/workflows/composer-require-checker.yml | 2 -- .github/workflows/rector.yml | 2 -- .github/workflows/static.yml | 2 -- 3 files changed, 6 deletions(-) diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index d58c1acc8..5b9d90bc2 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -24,8 +24,6 @@ jobs: composer-require-checker: uses: yiisoft/actions/.github/workflows/composer-require-checker.yml@install-subpackage with: - os: >- - ['ubuntu-latest'] php: >- ['8.1', '8.2', '8.3', '8.4'] subpackage: db diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index 8fe0e033a..cf6c36630 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -16,8 +16,6 @@ jobs: rector: uses: yiisoft/actions/.github/workflows/rector.yml@install-subpackage with: - os: >- - ['ubuntu-latest'] php: >- ['8.4'] subpackage: db diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 950024c43..e511a3293 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -24,8 +24,6 @@ jobs: psalm: uses: yiisoft/actions/.github/workflows/psalm.yml@install-subpackage with: - os: >- - ['ubuntu-latest'] php: >- ['8.1', '8.2', '8.3', '8.4'] subpackage: db From 0cafcf1d53229a0abce467d93123951be7f9955a Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 13 Apr 2025 22:43:28 +0700 Subject: [PATCH 15/29] Rerun tests --- .github/workflows/static.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index e511a3293..0a7687535 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -14,7 +14,7 @@ on: - 'psalm*.xml' - 'composer.json' -name: static analysis +name: Static analysis concurrency: group: ${{ github.workflow }}-${{ github.ref }} From 0d733eab206dde4f88ab63220061d7d69e16a1b5 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 13 Apr 2025 22:49:29 +0700 Subject: [PATCH 16/29] Rerun tests --- .github/workflows/rector.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index cf6c36630..912d8e814 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -6,7 +6,7 @@ on: - 'composer.json' - 'rector.php' -name: rector +name: Rector concurrency: group: ${{ github.workflow }}-${{ github.ref }} From 7639339f188034154342f03b9a6bafd1bf048531 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 14 Apr 2025 11:00:38 +0700 Subject: [PATCH 17/29] Update to changes in DB --- src/ActiveQuery.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php index 194b558bb..4c5a51f94 100644 --- a/src/ActiveQuery.php +++ b/src/ActiveQuery.php @@ -130,7 +130,7 @@ public function each(int $batchSize = 100): DataReaderInterface return $this->createCommand() ->query() ->indexBy($this->indexBy) - ->resultCallback($this->populate(...)); + ->resultCallback($this->populateOne(...)); } /** @@ -313,7 +313,7 @@ public function one(): array|ActiveRecordInterface|null return null; } - return $this->populate([$row])[0]; + return $this->populateOne($row); } /** @@ -945,4 +945,9 @@ private function createInstance(): static ->params($this->params) ->withQueries($this->withQueries); } + + private function populateOne(array $row): ActiveRecordInterface|array + { + return $this->populate([$row])[0]; + } } From 949b0a9cb6ea250507e6977873a33a5f4f3958f2 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 14 Apr 2025 11:10:17 +0700 Subject: [PATCH 18/29] Rerun tests --- .github/workflows/mutation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index e20a4756c..141fc49d0 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -12,7 +12,7 @@ on: - '.github/workflows/mutation.yml' - 'composer.json' -name: mutation +name: Mutation concurrency: group: ${{ github.workflow }}-${{ github.ref }} From 948bf7216f96b10e1c6aa061a641dec688305db1 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 14 Apr 2025 19:07:59 +0700 Subject: [PATCH 19/29] Rename `subpackage` to `required-package` in workflows --- .github/workflows/composer-require-checker.yml | 2 +- .github/workflows/db-mssql.yml | 8 ++++---- .github/workflows/db-mysql.yml | 8 ++++---- .github/workflows/db-oracle.yml | 8 ++++---- .github/workflows/db-pgsql.yml | 8 ++++---- .github/workflows/db-sqlite.yml | 8 ++++---- .github/workflows/mutation.yml | 8 ++++---- .github/workflows/rector.yml | 2 +- .github/workflows/static.yml | 2 +- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index 5b9d90bc2..974613413 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -26,4 +26,4 @@ jobs: with: php: >- ['8.1', '8.2', '8.3', '8.4'] - subpackage: db + required-package: db diff --git a/.github/workflows/db-mssql.yml b/.github/workflows/db-mssql.yml index 8d03fdbee..34ea46ec6 100644 --- a/.github/workflows/db-mssql.yml +++ b/.github/workflows/db-mssql.yml @@ -76,14 +76,14 @@ jobs: run: composer self-update - name: Install db. - uses: yiisoft/actions/install-subpackage@install-subpackage + uses: yiisoft/actions/install-required-package@install-subpackage with: - subpackage: db + required-package: db - name: Install db-mssql. - uses: yiisoft/actions/install-subpackage@install-subpackage + uses: yiisoft/actions/install-required-package@install-subpackage with: - subpackage: db-mssql + required-package: db-mssql - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Mssql --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/db-mysql.yml b/.github/workflows/db-mysql.yml index 0d3cca7de..a74b66b3d 100644 --- a/.github/workflows/db-mysql.yml +++ b/.github/workflows/db-mysql.yml @@ -68,14 +68,14 @@ jobs: run: composer self-update - name: Install db. - uses: yiisoft/actions/install-subpackage@install-subpackage + uses: yiisoft/actions/install-required-package@install-subpackage with: - subpackage: db + required-package: db - name: Install db-mysql. - uses: yiisoft/actions/install-subpackage@install-subpackage + uses: yiisoft/actions/install-required-package@install-subpackage with: - subpackage: db-mysql + required-package: db-mysql - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Mysql --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/db-oracle.yml b/.github/workflows/db-oracle.yml index 74a97bcf1..79dd770bf 100644 --- a/.github/workflows/db-oracle.yml +++ b/.github/workflows/db-oracle.yml @@ -74,14 +74,14 @@ jobs: run: composer self-update - name: Install db. - uses: yiisoft/actions/install-subpackage@install-subpackage + uses: yiisoft/actions/install-required-package@install-subpackage with: - subpackage: db + required-package: db - name: Install db-oracle. - uses: yiisoft/actions/install-subpackage@install-subpackage + uses: yiisoft/actions/install-required-package@install-subpackage with: - subpackage: db-oracle + required-package: db-oracle - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Oracle --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/db-pgsql.yml b/.github/workflows/db-pgsql.yml index 91adc5fc9..2bc14d5ad 100644 --- a/.github/workflows/db-pgsql.yml +++ b/.github/workflows/db-pgsql.yml @@ -68,14 +68,14 @@ jobs: run: composer self-update - name: Install db. - uses: yiisoft/actions/install-subpackage@install-subpackage + uses: yiisoft/actions/install-required-package@install-subpackage with: - subpackage: db + required-package: db - name: Install db-pgsql. - uses: yiisoft/actions/install-subpackage@install-subpackage + uses: yiisoft/actions/install-required-package@install-subpackage with: - subpackage: db-pgsql + required-package: db-pgsql - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Pgsql --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/db-sqlite.yml b/.github/workflows/db-sqlite.yml index 58f55dc35..aa5e6d104 100644 --- a/.github/workflows/db-sqlite.yml +++ b/.github/workflows/db-sqlite.yml @@ -61,15 +61,15 @@ jobs: run: composer self-update - name: Install db. - uses: yiisoft/actions/install-subpackage@install-subpackage + uses: yiisoft/actions/install-required-package@install-subpackage with: - subpackage: db + required-package: db os: ${{ matrix.os }} - name: Install db-sqlite. - uses: yiisoft/actions/install-subpackage@install-subpackage + uses: yiisoft/actions/install-required-package@install-subpackage with: - subpackage: db-sqlite + required-package: db-sqlite os: ${{ matrix.os }} - name: Run tests with phpunit. diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 141fc49d0..33e60496f 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -62,14 +62,14 @@ jobs: run: composer self-update - name: Install db. - uses: yiisoft/actions/install-subpackage@install-subpackage + uses: yiisoft/actions/install-required-package@install-subpackage with: - subpackage: db + required-package: db - name: Install db-pgsql. - uses: yiisoft/actions/install-subpackage@install-subpackage + uses: yiisoft/actions/install-required-package@install-subpackage with: - subpackage: db-pgsql + required-package: db-pgsql - name: Run infection. run: | diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index 912d8e814..caf74a647 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -18,4 +18,4 @@ jobs: with: php: >- ['8.4'] - subpackage: db + required-package: db diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 0a7687535..fd0f60e4b 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -26,4 +26,4 @@ jobs: with: php: >- ['8.1', '8.2', '8.3', '8.4'] - subpackage: db + required-package: db From 83fc70c118fc65c2363efd21a80cb6ec14cb382a Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 14 Apr 2025 20:36:58 +0700 Subject: [PATCH 20/29] Update --- .github/workflows/composer-require-checker.yml | 3 ++- .github/workflows/db-mssql.yml | 12 ++++-------- .github/workflows/db-mysql.yml | 12 ++++-------- .github/workflows/db-oracle.yml | 12 ++++-------- .github/workflows/db-pgsql.yml | 12 ++++-------- .github/workflows/db-sqlite.yml | 14 ++++---------- .github/workflows/mutation.yml | 12 ++++-------- .github/workflows/rector.yml | 3 ++- .github/workflows/static.yml | 3 ++- 9 files changed, 30 insertions(+), 53 deletions(-) diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index 974613413..086f50cdc 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -26,4 +26,5 @@ jobs: with: php: >- ['8.1', '8.2', '8.3', '8.4'] - required-package: db + required-packages: >- + ['db'] diff --git a/.github/workflows/db-mssql.yml b/.github/workflows/db-mssql.yml index 34ea46ec6..fe1860973 100644 --- a/.github/workflows/db-mssql.yml +++ b/.github/workflows/db-mssql.yml @@ -75,15 +75,11 @@ jobs: - name: Update composer. run: composer self-update - - name: Install db. - uses: yiisoft/actions/install-required-package@install-subpackage + - name: Install db and db-mssql. + uses: yiisoft/actions/install-packages@install-subpackage with: - required-package: db - - - name: Install db-mssql. - uses: yiisoft/actions/install-required-package@install-subpackage - with: - required-package: db-mssql + packages: >- + ['db', 'db-mssql'] - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Mssql --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/db-mysql.yml b/.github/workflows/db-mysql.yml index a74b66b3d..9b0fc20ce 100644 --- a/.github/workflows/db-mysql.yml +++ b/.github/workflows/db-mysql.yml @@ -67,15 +67,11 @@ jobs: - name: Update composer. run: composer self-update - - name: Install db. - uses: yiisoft/actions/install-required-package@install-subpackage + - name: Install db and db-mysql. + uses: yiisoft/actions/install-packages@install-subpackage with: - required-package: db - - - name: Install db-mysql. - uses: yiisoft/actions/install-required-package@install-subpackage - with: - required-package: db-mysql + packages: >- + ['db', 'db-mysql'] - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Mysql --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/db-oracle.yml b/.github/workflows/db-oracle.yml index 79dd770bf..c2890ba3b 100644 --- a/.github/workflows/db-oracle.yml +++ b/.github/workflows/db-oracle.yml @@ -73,15 +73,11 @@ jobs: - name: Update composer. run: composer self-update - - name: Install db. - uses: yiisoft/actions/install-required-package@install-subpackage + - name: Install db and db-oracle. + uses: yiisoft/actions/install-packages@install-subpackage with: - required-package: db - - - name: Install db-oracle. - uses: yiisoft/actions/install-required-package@install-subpackage - with: - required-package: db-oracle + packages: >- + ['db', 'db-oracle'] - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Oracle --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/db-pgsql.yml b/.github/workflows/db-pgsql.yml index 2bc14d5ad..8e9722507 100644 --- a/.github/workflows/db-pgsql.yml +++ b/.github/workflows/db-pgsql.yml @@ -67,15 +67,11 @@ jobs: - name: Update composer. run: composer self-update - - name: Install db. - uses: yiisoft/actions/install-required-package@install-subpackage + - name: Install db and db-pgsql. + uses: yiisoft/actions/install-packages@install-subpackage with: - required-package: db - - - name: Install db-pgsql. - uses: yiisoft/actions/install-required-package@install-subpackage - with: - required-package: db-pgsql + packages: >- + ['db', 'db-pgsql'] - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Pgsql --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/db-sqlite.yml b/.github/workflows/db-sqlite.yml index aa5e6d104..490af8b4c 100644 --- a/.github/workflows/db-sqlite.yml +++ b/.github/workflows/db-sqlite.yml @@ -60,17 +60,11 @@ jobs: - name: Update composer. run: composer self-update - - name: Install db. - uses: yiisoft/actions/install-required-package@install-subpackage + - name: Install db and db-sqlite. + uses: yiisoft/actions/install-packages@install-subpackage with: - required-package: db - os: ${{ matrix.os }} - - - name: Install db-sqlite. - uses: yiisoft/actions/install-required-package@install-subpackage - with: - required-package: db-sqlite - os: ${{ matrix.os }} + packages: >- + ['db', 'db-sqlite'] - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Sqlite --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 33e60496f..3e9084382 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -61,15 +61,11 @@ jobs: - name: Update composer. run: composer self-update - - name: Install db. - uses: yiisoft/actions/install-required-package@install-subpackage + - name: Install db and db-pgsql. + uses: yiisoft/actions/install-packages@install-subpackage with: - required-package: db - - - name: Install db-pgsql. - uses: yiisoft/actions/install-required-package@install-subpackage - with: - required-package: db-pgsql + packages: >- + ['db', 'db-pgsql'] - name: Run infection. run: | diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index caf74a647..5b966b8ff 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -18,4 +18,5 @@ jobs: with: php: >- ['8.4'] - required-package: db + required-packages: >- + ['db'] diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index fd0f60e4b..abf498c6d 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -26,4 +26,5 @@ jobs: with: php: >- ['8.1', '8.2', '8.3', '8.4'] - required-package: db + required-packages: >- + ['db'] From 7d768dfb63b675c52016fe5b7d22a6d91808de68 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 14 Apr 2025 20:45:35 +0700 Subject: [PATCH 21/29] Rerun tests --- .github/workflows/static.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index abf498c6d..4f72f3e3e 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -28,3 +28,4 @@ jobs: ['8.1', '8.2', '8.3', '8.4'] required-packages: >- ['db'] + From 7a5cbaee2ab02f7aa906a838ff1752b39196ff52 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 14 Apr 2025 20:54:10 +0700 Subject: [PATCH 22/29] Rerun tests --- .github/workflows/static.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 4f72f3e3e..abf498c6d 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -28,4 +28,3 @@ jobs: ['8.1', '8.2', '8.3', '8.4'] required-packages: >- ['db'] - From 6b3d5dc5de34d923266db814d4349aa33ff264e1 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 14 Apr 2025 21:14:39 +0700 Subject: [PATCH 23/29] Rerun tests --- .github/workflows/static.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index abf498c6d..4f72f3e3e 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -28,3 +28,4 @@ jobs: ['8.1', '8.2', '8.3', '8.4'] required-packages: >- ['db'] + From 099130c9f0e14b4afaf454996953b0fdeee913df Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 14 Apr 2025 21:19:43 +0700 Subject: [PATCH 24/29] Rerun tests --- .github/workflows/static.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 4f72f3e3e..abf498c6d 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -28,4 +28,3 @@ jobs: ['8.1', '8.2', '8.3', '8.4'] required-packages: >- ['db'] - From fb877397cfcc552ecc1f572e33c40a7b359a40b3 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 14 Apr 2025 21:26:11 +0700 Subject: [PATCH 25/29] Rerun tests --- .github/workflows/static.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index abf498c6d..4f72f3e3e 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -28,3 +28,4 @@ jobs: ['8.1', '8.2', '8.3', '8.4'] required-packages: >- ['db'] + From abf4529234116ae800b077727a2b99eaeccd2939 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 14 Apr 2025 21:29:10 +0700 Subject: [PATCH 26/29] Rerun tests --- .github/workflows/static.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 4f72f3e3e..abf498c6d 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -28,4 +28,3 @@ jobs: ['8.1', '8.2', '8.3', '8.4'] required-packages: >- ['db'] - From b0cf036702f849a56ca59a372b78292e1df53887 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 14 Apr 2025 21:35:34 +0700 Subject: [PATCH 27/29] Rerun tests --- .github/workflows/static.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index abf498c6d..4f72f3e3e 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -28,3 +28,4 @@ jobs: ['8.1', '8.2', '8.3', '8.4'] required-packages: >- ['db'] + From a309f5abc548a0692f0872acd736faa2998cfd33 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 15 Apr 2025 10:37:40 +0700 Subject: [PATCH 28/29] Change `@install-subpackage` to `@master` --- .github/workflows/composer-require-checker.yml | 2 +- .github/workflows/db-mssql.yml | 2 +- .github/workflows/db-mysql.yml | 2 +- .github/workflows/db-oracle.yml | 2 +- .github/workflows/db-pgsql.yml | 2 +- .github/workflows/db-sqlite.yml | 2 +- .github/workflows/mutation.yml | 2 +- .github/workflows/rector.yml | 2 +- .github/workflows/static.yml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index 086f50cdc..1face1f24 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -22,7 +22,7 @@ concurrency: jobs: composer-require-checker: - uses: yiisoft/actions/.github/workflows/composer-require-checker.yml@install-subpackage + uses: yiisoft/actions/.github/workflows/composer-require-checker.yml@master with: php: >- ['8.1', '8.2', '8.3', '8.4'] diff --git a/.github/workflows/db-mssql.yml b/.github/workflows/db-mssql.yml index fe1860973..c752d0198 100644 --- a/.github/workflows/db-mssql.yml +++ b/.github/workflows/db-mssql.yml @@ -76,7 +76,7 @@ jobs: run: composer self-update - name: Install db and db-mssql. - uses: yiisoft/actions/install-packages@install-subpackage + uses: yiisoft/actions/install-packages@master with: packages: >- ['db', 'db-mssql'] diff --git a/.github/workflows/db-mysql.yml b/.github/workflows/db-mysql.yml index 9b0fc20ce..4db6bff0a 100644 --- a/.github/workflows/db-mysql.yml +++ b/.github/workflows/db-mysql.yml @@ -68,7 +68,7 @@ jobs: run: composer self-update - name: Install db and db-mysql. - uses: yiisoft/actions/install-packages@install-subpackage + uses: yiisoft/actions/install-packages@master with: packages: >- ['db', 'db-mysql'] diff --git a/.github/workflows/db-oracle.yml b/.github/workflows/db-oracle.yml index c2890ba3b..1a44efdf9 100644 --- a/.github/workflows/db-oracle.yml +++ b/.github/workflows/db-oracle.yml @@ -74,7 +74,7 @@ jobs: run: composer self-update - name: Install db and db-oracle. - uses: yiisoft/actions/install-packages@install-subpackage + uses: yiisoft/actions/install-packages@master with: packages: >- ['db', 'db-oracle'] diff --git a/.github/workflows/db-pgsql.yml b/.github/workflows/db-pgsql.yml index 8e9722507..8bb745aa4 100644 --- a/.github/workflows/db-pgsql.yml +++ b/.github/workflows/db-pgsql.yml @@ -68,7 +68,7 @@ jobs: run: composer self-update - name: Install db and db-pgsql. - uses: yiisoft/actions/install-packages@install-subpackage + uses: yiisoft/actions/install-packages@master with: packages: >- ['db', 'db-pgsql'] diff --git a/.github/workflows/db-sqlite.yml b/.github/workflows/db-sqlite.yml index 490af8b4c..3b8528d64 100644 --- a/.github/workflows/db-sqlite.yml +++ b/.github/workflows/db-sqlite.yml @@ -61,7 +61,7 @@ jobs: run: composer self-update - name: Install db and db-sqlite. - uses: yiisoft/actions/install-packages@install-subpackage + uses: yiisoft/actions/install-packages@master with: packages: >- ['db', 'db-sqlite'] diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 3e9084382..cb3700a9f 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -62,7 +62,7 @@ jobs: run: composer self-update - name: Install db and db-pgsql. - uses: yiisoft/actions/install-packages@install-subpackage + uses: yiisoft/actions/install-packages@master with: packages: >- ['db', 'db-pgsql'] diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index 5b966b8ff..33529155b 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -14,7 +14,7 @@ concurrency: jobs: rector: - uses: yiisoft/actions/.github/workflows/rector.yml@install-subpackage + uses: yiisoft/actions/.github/workflows/rector.yml@master with: php: >- ['8.4'] diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 4f72f3e3e..5153d22f1 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -22,7 +22,7 @@ concurrency: jobs: psalm: - uses: yiisoft/actions/.github/workflows/psalm.yml@install-subpackage + uses: yiisoft/actions/.github/workflows/psalm.yml@master with: php: >- ['8.1', '8.2', '8.3', '8.4'] From 16d8a2b1f345091fb177914257da92a56593ae09 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 16 Apr 2025 14:45:53 +0700 Subject: [PATCH 29/29] Remove `$batchSize` parameter from `ActiveQuery::each()` --- src/ActiveQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php index 9c5eb3a0e..62b833dcc 100644 --- a/src/ActiveQuery.php +++ b/src/ActiveQuery.php @@ -124,7 +124,7 @@ final public function __construct( parent::__construct($this->getARInstance()->db()); } - public function each(int $batchSize = 100): DataReaderInterface + public function each(): DataReaderInterface { /** @psalm-suppress InvalidArgument */ return $this->createCommand()