Skip to content

Commit

Permalink
Make ActiveQuery::getARClassName() private
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Jun 25, 2024
1 parent e3c7c6e commit 0658a76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions src/ActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActiveRecordInterface> $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<ActiveRecordInterface> $class */
$class = $this->arClass;

return new $class($this->db, $this->tableName);
return $this->arClass;
}

private function createInstance(): static
Expand Down
6 changes: 3 additions & 3 deletions tests/ActiveQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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());
}

Expand All @@ -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());
}
}

0 comments on commit 0658a76

Please sign in to comment.