Skip to content

Commit

Permalink
add appendQuery function to reduce duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
devmoath committed Oct 29, 2021
1 parent 79f4b6a commit 93c904f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Jql.php
Expand Up @@ -69,13 +69,7 @@ public function where(string $column, string $operator, mixed $value, string $bo
{
$this->invalidBoolean($boolean);

return tap($this, function() use ($column, $operator, $value, $boolean) {
if (empty($this->query)) {
$this->query = "$column $operator {$this->quote($operator, $value)}";
} else {
$this->query .= " $boolean $column $operator {$this->quote($operator, $value)}";
}
});
return tap($this, fn() => $this->appendQuery("$column $operator {$this->quote($operator, $value)}", $boolean));
}

public function orWhere(string $column, string $operator, mixed $value): self
Expand Down Expand Up @@ -172,6 +166,15 @@ public function getQuery(): string
return trim($this->query);
}

public function appendQuery(string $query, string $boolean = ''): void
{
if (empty($this->query)) {
$this->query = $query;
} else {
$this->query .= " $boolean $query";
}
}

public function __toString(): string
{
return $this->getQuery();
Expand Down

0 comments on commit 93c904f

Please sign in to comment.