From 0658a76d74844de9a597c79dfa647a5f9b46a51e Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 25 Jun 2024 14:35:18 +0700 Subject: [PATCH] Make `ActiveQuery::getARClassName()` private --- src/ActiveQuery.php | 22 +++++++++++----------- tests/ActiveQueryTest.php | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php index 0b2a18567..b0461d024 100644 --- a/src/ActiveQuery.php +++ b/src/ActiveQuery.php @@ -976,33 +976,33 @@ public function sql(string|null $value): self return $this; } - public function getARClassName(): string + public function getARInstance(): ActiveRecordInterface { if ($this->arClass instanceof ActiveRecordInterface) { - return $this->arClass::class; + return clone $this->arClass; } if ($this->arClass instanceof Closure) { - return ($this->arClass)($this->db)::class; + return ($this->arClass)($this->db); } - return $this->arClass; + /** @psalm-var class-string $class */ + $class = $this->arClass; + + return new $class($this->db, $this->tableName); } - public function getARInstance(): ActiveRecordInterface + private function getARClassName(): string { if ($this->arClass instanceof ActiveRecordInterface) { - return clone $this->arClass; + return $this->arClass::class; } if ($this->arClass instanceof Closure) { - return ($this->arClass)($this->db); + return ($this->arClass)($this->db)::class; } - /** @psalm-var class-string $class */ - $class = $this->arClass; - - return new $class($this->db, $this->tableName); + return $this->arClass; } private function createInstance(): static diff --git a/tests/ActiveQueryTest.php b/tests/ActiveQueryTest.php index 84174f5f4..687d3a366 100644 --- a/tests/ActiveQueryTest.php +++ b/tests/ActiveQueryTest.php @@ -2671,7 +2671,7 @@ public function testARClassAsString(): void $query = new ActiveQuery(Customer::class, $this->db); $this->assertSame($query->getARClass(), Customer::class); - $this->assertSame($query->getARClassName(), Customer::class); + $this->assertSame(Assert::invokeMethod($query, 'getARClassName'), Customer::class); $this->assertInstanceOf(Customer::class, $query->getARInstance()); } @@ -2681,7 +2681,7 @@ public function testARClassAsInstance(): void $query = new ActiveQuery($customer, $this->db); $this->assertSame($query->getARClass(), $customer); - $this->assertSame($query->getARClassName(), Customer::class); + $this->assertSame(Assert::invokeMethod($query, 'getARClassName'), Customer::class); $this->assertInstanceOf(Customer::class, $query->getARInstance()); } @@ -2691,7 +2691,7 @@ public function testARClassAsClosure(): void $query = new ActiveQuery($closure, $this->db); $this->assertSame($query->getARClass(), $closure); - $this->assertSame($query->getARClassName(), Customer::class); + $this->assertSame(Assert::invokeMethod($query, 'getARClassName'), Customer::class); $this->assertInstanceOf(Customer::class, $query->getARInstance()); } }