Skip to content

Commit

Permalink
Add factory method for Column (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalcrazz committed Jan 13, 2021
1 parent 9a5f101 commit 1d315f5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Query/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ public function addSelect(...$columns)
return $this;
}

/**
* A factory method for Column.
*
* @return Column
*/
protected function makeColumn(): Column
{
return new Column($this);
}

/**
* Prepares columns given by user to Column objects.
*
Expand All @@ -242,7 +252,7 @@ protected function processColumns(array $columns, bool $withAliases = true): arr
foreach ($columns as $column => $value) {
if ($value instanceof Closure) {
$columnName = $column;
$column = (new Column($this));
$column = $this->makeColumn();

if (!is_int($columnName)) {
$column->name($columnName);
Expand All @@ -257,7 +267,7 @@ protected function processColumns(array $columns, bool $withAliases = true): arr

if ($value instanceof BaseBuilder) {
$alias = is_string($column) ? $column : null;
$column = (new Column($this))->query($value);
$column = $this->makeColumn()->query($value);

if (!is_null($alias) && $withAliases) {
$column->as($alias);
Expand All @@ -272,7 +282,7 @@ protected function processColumns(array $columns, bool $withAliases = true): arr
if (!$column instanceof Column) {
$alias = is_string($value) ? $value : null;

$column = (new Column($this))->name($column);
$column = $this->makeColumn()->name($column);

if (!is_null($alias) && $withAliases) {
$column->as($alias);
Expand Down

0 comments on commit 1d315f5

Please sign in to comment.