Skip to content

Commit

Permalink
Fix #642: Remove unsed Stringable in Query::class (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Apr 4, 2023
1 parent 1d1b646 commit 9320d8e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 30 deletions.
9 changes: 0 additions & 9 deletions src/Query/Query.php
Expand Up @@ -29,7 +29,6 @@
use function preg_match;
use function preg_split;
use function reset;
use function serialize;
use function str_contains;
use function strcasecmp;
use function strlen;
Expand Down Expand Up @@ -93,14 +92,6 @@ public function __construct(protected ConnectionInterface $db)
{
}

/**
* Returns the SQL representation of Query.
*/
public function __toString(): string
{
return serialize($this);
}

public function addGroupBy(array|string|ExpressionInterface $columns): static
{
if ($columns instanceof ExpressionInterface) {
Expand Down
3 changes: 1 addition & 2 deletions src/Query/QueryInterface.php
Expand Up @@ -5,7 +5,6 @@
namespace Yiisoft\Db\Query;

use Closure;
use Stringable;
use Throwable;
use Yiisoft\Db\Command\CommandInterface;
use Yiisoft\Db\Exception\Exception;
Expand All @@ -27,7 +26,7 @@
*
* Sorting is supported via {@see orderBy()} and items can be limited to match some conditions using {@see where()}.
*/
interface QueryInterface extends ExpressionInterface, QueryPartsInterface, QueryFunctionsInterface, Stringable
interface QueryInterface extends ExpressionInterface, QueryPartsInterface, QueryFunctionsInterface
{
/**
* Adds more parameters to biun to the query.
Expand Down
16 changes: 7 additions & 9 deletions src/QueryBuilder/AbstractDQLQueryBuilder.php
Expand Up @@ -382,14 +382,13 @@ public function buildUnion(array $unions, array &$params): string

$result = '';

/** @psalm-var array<array{query:Query|string, all:bool}> $unions */
foreach ($unions as $i => $union) {
$query = $union['query'];
if ($query instanceof QueryInterface) {
[$unions[$i]['query'], $params] = $this->build($query, $params);
/** @psalm-var array<array{query:string|Query, all:bool}> $unions */
foreach ($unions as $union) {
if ($union['query'] instanceof QueryInterface) {
[$union['query'], $params] = $this->build($union['query'], $params);
}

$result .= 'UNION ' . ($union['all'] ? 'ALL ' : '') . '( ' . $unions[$i]['query'] . ' ) ';
$result .= 'UNION ' . ($union['all'] ? 'ALL ' : '') . '( ' . $union['query'] . ' ) ';
}

return trim($result);
Expand Down Expand Up @@ -418,9 +417,8 @@ public function buildWithQueries(array $withs, array &$params): string
$recursive = true;
}

$query = $with['query'];
if ($query instanceof QueryInterface) {
[$with['query'], $params] = $this->build($query, $params);
if ($with['query'] instanceof QueryInterface) {
[$with['query'], $params] = $this->build($with['query'], $params);
}

$result[] = $with['alias'] . ' AS (' . $with['query'] . ')';
Expand Down
10 changes: 0 additions & 10 deletions tests/AbstractQueryTest.php
Expand Up @@ -696,16 +696,6 @@ public function testShouldEmulateExecution(): void
$this->assertTrue($query->shouldEmulateExecution());
}

public function testToString(): void
{
$db = $this->getConnection();

$query = new Query($db);
$query->select('id')->from('user')->where(['id' => 1]);

$this->assertSame(serialize($query), (string)$query);
}

public function testWhere(): void
{
$db = $this->getConnection();
Expand Down

0 comments on commit 9320d8e

Please sign in to comment.