Skip to content

Commit 893795b

Browse files
committed
Make Table properties public, remove accessor methods
Expose From, Columns, and Join as public properties on Table, eliminating three method calls per buildSqlString invocation.
1 parent 4e4d2f9 commit 893795b

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

src/Sql/Part/Table.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
class Table
2323
{
24-
private From $from;
25-
private Columns $columns;
26-
private ?Join $join = null;
24+
public From $from;
25+
public Columns $columns;
26+
public ?Join $join = null;
2727

2828
public function __construct()
2929
{
@@ -144,21 +144,6 @@ public function resetJoins(): static
144144
return $this;
145145
}
146146

147-
public function from(): From
148-
{
149-
return $this->from;
150-
}
151-
152-
public function columns(): Columns
153-
{
154-
return $this->columns;
155-
}
156-
157-
public function joins(): ?Join
158-
{
159-
return $this->join;
160-
}
161-
162147
public function __clone()
163148
{
164149
$this->from = clone $this->from;

src/Sql/Select.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public function getRawState(?string $key = null): mixed
350350
self::TABLE => $this->table->getFrom(),
351351
self::QUANTIFIER => $this->quantifier?->get(),
352352
self::COLUMNS => $this->table->getColumns(),
353-
self::JOINS => $this->table->joins() ?? new Join(),
353+
self::JOINS => $this->table->join ?? new Join(),
354354
self::WHERE => $this->where ??= new Where(),
355355
self::ORDER => $this->orderBy?->get() ?? [],
356356
self::GROUP => $this->groupBy?->get() ?? [],
@@ -380,12 +380,13 @@ public function buildSqlString(AbstractSqlRenderer $renderer): string
380380
{
381381
$renderer->getTypeDecorator($this)?->prepare($this, $renderer);
382382

383+
$combine = $this->combine?->toSql($renderer);
384+
383385
$sql = implode(' ', array_filter([
384-
'SELECT',
385386
$this->quantifier?->toSql($renderer),
386-
$this->table->columns()->toSql($renderer),
387-
$this->table->from()->toSql($renderer),
388-
$this->table->joins()?->toSql($renderer),
387+
$this->table->columns->toSql($renderer),
388+
$this->table->from->toSql($renderer),
389+
$this->table->join?->toSql($renderer),
389390
$this->where?->toSql($renderer),
390391
$this->groupBy?->toSql($renderer),
391392
$this->having?->toSql($renderer),
@@ -394,9 +395,9 @@ public function buildSqlString(AbstractSqlRenderer $renderer): string
394395
$this->offset?->toSql($renderer),
395396
]));
396397

397-
$combine = $this->combine?->toSql($renderer);
398-
399-
return $combine !== null ? "( $sql ) $combine" : $sql;
398+
return $combine !== null
399+
? "( SELECT $sql ) $combine"
400+
: "SELECT $sql";
400401
}
401402

402403
/**
@@ -412,7 +413,7 @@ public function __get(string $name): Where|Join|Having
412413
case 'having':
413414
return $this->having ??= new Having();
414415
case 'joins':
415-
return $this->table->joins() ?? new Join();
416+
return $this->table->join ?? new Join();
416417
default:
417418
throw new Exception\InvalidArgumentException('Not a valid magic property for this object');
418419
}

0 commit comments

Comments
 (0)