diff --git a/src/AbstractActiveRecord.php b/src/AbstractActiveRecord.php index 5bcd471b3..07ff31864 100644 --- a/src/AbstractActiveRecord.php +++ b/src/AbstractActiveRecord.php @@ -432,7 +432,7 @@ public function link(string $relationName, ActiveRecordInterface $arClass, array if (is_array($via)) { [$viaName, $viaRelation] = $via; /** @psalm-var ActiveQueryInterface $viaRelation */ - $viaClass = $viaRelation->getARInstance(); + $viaClass = $viaRelation->getArInstance(); // unset $viaName so that it can be reloaded to reflect the change. /** @psalm-var string $viaName */ unset($this->related[$viaName]); @@ -825,7 +825,7 @@ public function unlink(string $relationName, ActiveRecordInterface $arClass, boo if (is_array($viaRelation)) { [$viaName, $viaRelation] = $viaRelation; /** @psalm-var ActiveQueryInterface $viaRelation */ - $viaClass = $viaRelation->getARInstance(); + $viaClass = $viaRelation->getArInstance(); /** @psalm-var string $viaName */ unset($this->related[$viaName]); } @@ -941,7 +941,7 @@ public function unlinkAll(string $relationName, bool $delete = false): void if (is_array($viaRelation)) { [$viaName, $viaRelation] = $viaRelation; /** @psalm-var ActiveQueryInterface $viaRelation */ - $viaClass = $viaRelation->getARInstance(); + $viaClass = $viaRelation->getArInstance(); /** @psalm-var string $viaName */ unset($this->related[$viaName]); } else { @@ -984,7 +984,7 @@ public function unlinkAll(string $relationName, bool $delete = false): void } } } else { - $relatedModel = $relation->getARInstance(); + $relatedModel = $relation->getArInstance(); $link = $relation->getLink(); if (!$delete && count($link) === 1 && is_array($this->get($b = reset($link)))) { diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php index 688b7a3e1..82036c8cb 100644 --- a/src/ActiveQuery.php +++ b/src/ActiveQuery.php @@ -120,7 +120,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface final public function __construct( protected string|ActiveRecordInterface|Closure $arClass ) { - parent::__construct($this->getARInstance()->db()); + parent::__construct($this->getArInstance()->db()); } public function each(): DataReaderInterface @@ -273,7 +273,7 @@ public function populate(array $rows): array */ private function removeDuplicatedRows(array $rows): array { - $instance = $this->getARInstance(); + $instance = $this->getArInstance(); $pks = $instance->primaryKey(); if (empty($pks)) { @@ -416,7 +416,7 @@ public function buildJoinWith(): void $this->join = []; - $arClass = $this->getARInstance(); + $arClass = $this->getArInstance(); foreach ($this->joinWith as [$with, $eagerLoading, $joinType]) { $this->joinWithRelations($arClass, $with, $joinType); @@ -517,7 +517,7 @@ private function joinWithRelations(ActiveRecordInterface $arClass, array $with, } if ($relation instanceof ActiveQueryInterface) { - $primaryModel = $relation->getARInstance(); + $primaryModel = $relation->getArInstance(); $parent = $relation; } @@ -779,7 +779,7 @@ public function getTablesUsedInFrom(): array protected function getPrimaryTableName(): string { - return $this->getARInstance()->tableName(); + return $this->getArInstance()->tableName(); } public function getOn(): array|string|null @@ -800,7 +800,7 @@ public function getSql(): string|null return $this->sql; } - public function getARClass(): string|ActiveRecordInterface|Closure + public function getArClass(): string|ActiveRecordInterface|Closure { return $this->arClass; } @@ -809,7 +809,7 @@ public function findByPk(array|float|int|string $values): array|ActiveRecordInte { $values = (array) $values; - $arInstance = $this->getARInstance(); + $arInstance = $this->getArInstance(); $primaryKey = $arInstance->primaryKey(); if (empty($primaryKey)) { @@ -845,7 +845,7 @@ public function sql(string|null $value): static return $this; } - public function getARInstance(): ActiveRecordInterface + public function getArInstance(): ActiveRecordInterface { if ($this->arClass instanceof ActiveRecordInterface) { return clone $this->arClass; diff --git a/src/ActiveQueryInterface.php b/src/ActiveQueryInterface.php index 451f369e1..3cd7060d4 100644 --- a/src/ActiveQueryInterface.php +++ b/src/ActiveQueryInterface.php @@ -317,7 +317,7 @@ public function getSql(): string|null; * * @psalm-return ARClass */ - public function getARClass(): string|ActiveRecordInterface|Closure; + public function getArClass(): string|ActiveRecordInterface|Closure; public function on(array|string|null $value): static; @@ -455,7 +455,7 @@ public function getLink(): array; * @throws NotInstantiableException * @return ActiveRecordInterface The model instance associated with this query. */ - public function getARInstance(): ActiveRecordInterface; + public function getArInstance(): ActiveRecordInterface; /** * @return bool Whether this query represents a relation to more than one record. diff --git a/src/ActiveQueryTrait.php b/src/ActiveQueryTrait.php index 0ba392db6..982ed5c85 100644 --- a/src/ActiveQueryTrait.php +++ b/src/ActiveQueryTrait.php @@ -129,7 +129,7 @@ protected function createModels(array $rows): array $models = []; foreach ($rows as $row) { - $arClass = $this->getARInstance(); + $arClass = $this->getArInstance(); $arClass->populateRecord($row); $models[] = $arClass; @@ -159,7 +159,7 @@ public function findWith(array $with, array &$models): void $primaryModel = reset($models); if (!$primaryModel instanceof ActiveRecordInterface) { - $primaryModel = $this->getARInstance(); + $primaryModel = $this->getArInstance(); } $relations = $this->normalizeRelations($primaryModel, $with); diff --git a/src/ActiveRelationTrait.php b/src/ActiveRelationTrait.php index 15ca3888c..eadea8736 100644 --- a/src/ActiveRelationTrait.php +++ b/src/ActiveRelationTrait.php @@ -223,7 +223,7 @@ private function addInverseRelations(array &$result): void $relatedModel->populateRelation($this->inverseOf, $primaryModel); } } else { - $inverseRelation = $this->getARInstance()->relationQuery($this->inverseOf); + $inverseRelation = $this->getArInstance()->relationQuery($this->inverseOf); $primaryModel = $inverseRelation->getMultiple() ? [$this->primaryModel] : $this->primaryModel; /** @var array $relatedModel */ @@ -338,7 +338,7 @@ private function populateInverseRelation( /** @var ActiveQuery $relation */ $relation = is_array($model) - ? $this->getARInstance()->relationQuery($name) + ? $this->getArInstance()->relationQuery($name) : $model->relationQuery($name); $link = $relation->getLink(); @@ -492,7 +492,7 @@ private function prefixKeyColumns(array $columnNames): array { if (!empty($this->join) || !empty($this->joinWith)) { if (empty($this->from)) { - $alias = $this->getARInstance()->tableName(); + $alias = $this->getArInstance()->tableName(); } else { $alias = array_key_first($this->from); @@ -570,7 +570,7 @@ protected function filterByModels(array $models): void /** @var string $propertyName */ $propertyName = array_key_first($this->link); - match ($this->getARInstance()->columnType($propertyName)) { + match ($this->getArInstance()->columnType($propertyName)) { ColumnType::ARRAY => $this->andWhere(new ArrayOverlapsCondition($columnName, $values)), ColumnType::JSON => $this->andWhere(new JsonOverlapsCondition($columnName, $values)), default => $this->andWhere(new InCondition($columnName, 'IN', $values)), diff --git a/tests/ActiveQueryTest.php b/tests/ActiveQueryTest.php index 8e72a5c55..bea896f84 100644 --- a/tests/ActiveQueryTest.php +++ b/tests/ActiveQueryTest.php @@ -40,7 +40,7 @@ public function testOptions(): void $customerQuery = new ActiveQuery(Customer::class); $query = $customerQuery->on(['a' => 'b'])->joinWith('profile'); - $this->assertEquals(Customer::class, $query->getARClass()); + $this->assertEquals(Customer::class, $query->getArClass()); $this->assertEquals(['a' => 'b'], $query->getOn()); $this->assertEquals([[['profile'], true, 'LEFT JOIN']], $query->getJoinWith()); $customerQuery->resetJoinWith(); @@ -2499,29 +2499,29 @@ public function testEqual(): void $this->assertFalse($customerA->equals($customerB)); } - public function testARClassAsString(): void + public function testArClassAsString(): void { $query = new ActiveQuery(Customer::class); - $this->assertSame(Customer::class, $query->getARClass()); - $this->assertInstanceOf(Customer::class, $query->getARInstance()); + $this->assertSame(Customer::class, $query->getArClass()); + $this->assertInstanceOf(Customer::class, $query->getArInstance()); } - public function testARClassAsInstance(): void + public function testArClassAsInstance(): void { $customer = new Customer(); $query = new ActiveQuery($customer); - $this->assertSame($customer, $query->getARClass()); - $this->assertInstanceOf(Customer::class, $query->getARInstance()); + $this->assertSame($customer, $query->getArClass()); + $this->assertInstanceOf(Customer::class, $query->getArInstance()); } - public function testARClassAsClosure(): void + public function testArClassAsClosure(): void { $closure = fn (): Customer => new Customer(); $query = new ActiveQuery($closure); - $this->assertSame($closure, $query->getARClass()); - $this->assertInstanceOf(Customer::class, $query->getARInstance()); + $this->assertSame($closure, $query->getArClass()); + $this->assertInstanceOf(Customer::class, $query->getArInstance()); } }