From a4f550ecedb5f0121ce68827baf1678810026054 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 24 Aug 2025 21:01:07 +0700 Subject: [PATCH 1/6] Improve array and JSON overlaps --- src/.meta-storm.xml | 2 +- src/ActiveRecord.php | 7 ++++--- src/ActiveRecordInterface.php | 8 +++----- src/ActiveRelationTrait.php | 8 ++++++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/.meta-storm.xml b/src/.meta-storm.xml index 8ea9cb701..50c46c2e3 100644 --- a/src/.meta-storm.xml +++ b/src/.meta-storm.xml @@ -10,7 +10,7 @@ - + diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index c72f64858..fda5be36f 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -4,10 +4,11 @@ namespace Yiisoft\ActiveRecord; -use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidCallException; use Yiisoft\Db\Exception\InvalidConfigException; +use Yiisoft\Db\Schema\Column\ColumnInterface; +use Yiisoft\Db\Schema\Column\StringColumn; use Yiisoft\Db\Schema\TableSchemaInterface; use function array_diff_key; @@ -84,9 +85,9 @@ public function propertyNames(): array return $this->tableSchema()->getColumnNames(); } - public function columnType(string $propertyName): string + public function column(string $propertyName): ColumnInterface { - return $this->tableSchema()->getColumn($propertyName)?->getType() ?? ColumnType::STRING; + return $this->tableSchema()->getColumn($propertyName) ?? new StringColumn(name: $propertyName); } /** diff --git a/src/ActiveRecordInterface.php b/src/ActiveRecordInterface.php index 7f79ae16a..cca906b6a 100644 --- a/src/ActiveRecordInterface.php +++ b/src/ActiveRecordInterface.php @@ -6,11 +6,11 @@ use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; -use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Exception\Exception; use InvalidArgumentException; use Yiisoft\Db\Exception\InvalidCallException; use Yiisoft\Db\Exception\InvalidConfigException; +use Yiisoft\Db\Schema\Column\ColumnInterface; /** * @psalm-import-type ModelClass from ActiveQuery @@ -27,11 +27,9 @@ interface ActiveRecordInterface public function propertyNames(): array; /** - * Returns the abstract type of the property. - * - * @psalm-return ColumnType::* + * @return ColumnInterface The column instance of the property. */ - public function columnType(string $propertyName): string; + public function column(string $propertyName): ColumnInterface; /** * Create {@see ActiveQueryInterface} instance for the given model class. diff --git a/src/ActiveRelationTrait.php b/src/ActiveRelationTrait.php index e528f411a..f3c7fa506 100644 --- a/src/ActiveRelationTrait.php +++ b/src/ActiveRelationTrait.php @@ -11,9 +11,12 @@ use Yiisoft\Db\Exception\Exception; use InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; +use Yiisoft\Db\Expression\ArrayExpression; use Yiisoft\Db\QueryBuilder\Condition\In; use Yiisoft\Db\QueryBuilder\Condition\ArrayOverlaps; use Yiisoft\Db\QueryBuilder\Condition\JsonOverlaps; +use Yiisoft\Db\Schema\Column\AbstractArrayColumn; +use Yiisoft\Db\Schema\Column\AbstractJsonColumn; use function array_column; use function array_combine; @@ -569,9 +572,10 @@ protected function filterByModels(array $models): void $columnName = reset($columnNames); /** @var string $propertyName */ $propertyName = array_key_first($this->link); + $column = $this->getModel()->column($propertyName); - match ($this->getModel()->columnType($propertyName)) { - ColumnType::ARRAY => $this->andWhere(new ArrayOverlaps($columnName, $values)), + match ($column->getType()) { + ColumnType::ARRAY => $this->andWhere(new ArrayOverlaps($columnName, new ArrayExpression($values, $column))), ColumnType::JSON => $this->andWhere(new JsonOverlaps($columnName, $values)), default => $this->andWhere(new In($columnName, $values)), }; From 5678c508bf2739e5f6d5f1f15bc493d507e0fcf9 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 24 Aug 2025 14:11:13 +0000 Subject: [PATCH 2/6] Apply fixes from StyleCI --- src/ActiveRelationTrait.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ActiveRelationTrait.php b/src/ActiveRelationTrait.php index f3c7fa506..2a1892a60 100644 --- a/src/ActiveRelationTrait.php +++ b/src/ActiveRelationTrait.php @@ -15,8 +15,6 @@ use Yiisoft\Db\QueryBuilder\Condition\In; use Yiisoft\Db\QueryBuilder\Condition\ArrayOverlaps; use Yiisoft\Db\QueryBuilder\Condition\JsonOverlaps; -use Yiisoft\Db\Schema\Column\AbstractArrayColumn; -use Yiisoft\Db\Schema\Column\AbstractJsonColumn; use function array_column; use function array_combine; From 6ec553c692105687dc14288a7405412ec5c54e93 Mon Sep 17 00:00:00 2001 From: Tigrov <8563175+Tigrov@users.noreply.github.com> Date: Sun, 24 Aug 2025 14:14:31 +0000 Subject: [PATCH 3/6] Apply Rector changes (CI) --- tests/Support/Assert.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/Support/Assert.php b/tests/Support/Assert.php index 7eaaf2e69..6b2345b8a 100644 --- a/tests/Support/Assert.php +++ b/tests/Support/Assert.php @@ -44,8 +44,6 @@ public static function inaccessibleProperty(object $object, string $propertyName if ($propertyName !== '') { $property = $class->getProperty($propertyName); - $property->setAccessible(true); - /** @psalm-var mixed $result */ $result = $property->getValue($object); } @@ -69,8 +67,6 @@ public static function invokeMethod(object $object, string $method, array $args if ($method !== '') { $method = $reflection->getMethod($method); - $method->setAccessible(true); - /** @psalm-var mixed $result */ $result = $method->invokeArgs($object, $args); } From b57f9da5024b76c9b408baab6c7b24bde65ea10c Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 24 Aug 2025 21:15:25 +0700 Subject: [PATCH 4/6] Improve --- src/ActiveRecord.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index fda5be36f..12fb7a997 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -87,7 +87,8 @@ public function propertyNames(): array public function column(string $propertyName): ColumnInterface { - return $this->tableSchema()->getColumn($propertyName) ?? new StringColumn(name: $propertyName); + return $this->tableSchema()->getColumn($propertyName) + ?? $this->db()->getColumnBuilderClass()::string()->withName($propertyName); } /** From a879fc6553a5f9cc8a9e25b68cd6d662a90c166d Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 24 Aug 2025 21:18:26 +0700 Subject: [PATCH 5/6] Improve --- src/ActiveRecord.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index 12fb7a997..40d1ec8cb 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -4,6 +4,7 @@ namespace Yiisoft\ActiveRecord; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidCallException; use Yiisoft\Db\Exception\InvalidConfigException; @@ -88,7 +89,7 @@ public function propertyNames(): array public function column(string $propertyName): ColumnInterface { return $this->tableSchema()->getColumn($propertyName) - ?? $this->db()->getColumnBuilderClass()::string()->withName($propertyName); + ?? $this->db()->getColumnFactory()->fromType(ColumnType::STRING, ['name' => $propertyName]); } /** From d395c357ec1964edf7445a44032d18cf1868023d Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 24 Aug 2025 14:18:42 +0000 Subject: [PATCH 6/6] Apply fixes from StyleCI --- src/ActiveRecord.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index 40d1ec8cb..3b38745e6 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -9,7 +9,6 @@ use Yiisoft\Db\Exception\InvalidCallException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Schema\Column\ColumnInterface; -use Yiisoft\Db\Schema\Column\StringColumn; use Yiisoft\Db\Schema\TableSchemaInterface; use function array_diff_key;