Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
selahattinunlu committed Oct 4, 2015
1 parent 8a3ea19 commit bba71cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
24 changes: 12 additions & 12 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function prepare()

$constantParameters = $this->uriParser->constantParameters();

array_map([$this, 'prepareConstants'], $constantParameters);
array_map([$this, 'prepareConstant'], $constantParameters);

if ($this->hasIncludes() && $this->hasRelationColumns()) {
$this->fixRelationColumns();
Expand Down Expand Up @@ -108,20 +108,20 @@ protected function build()
return $this->query;
}

private function prepareConstants($exceptKey)
private function prepareConstant($parameter)
{
if (! $this->uriParser->hasQueryParameter($exceptKey)) return;
if (! $this->uriParser->hasQueryParameter($parameter)) return;

$callback = [$this, $this->setterMethodName($exceptKey)];
$callback = [$this, $this->setterMethodName($parameter)];

$callbackParameter = $this->uriParser->queryParameter($exceptKey);
$callbackParameter = $this->uriParser->queryParameter($parameter);

call_user_func($callback, $callbackParameter['value']);
}

private function setIncludes($includes)
{
$this->includes = explode(',', $includes);
$this->includes = array_filter(explode(',', $includes));
}

private function setPage($page)
Expand Down Expand Up @@ -149,9 +149,9 @@ private function setColumn($column)
$this->columns[] = $column;
}

private function appendRelationColumn($column)
private function appendRelationColumn($keyAndColumn)
{
list($key, $column) = explode('.', $column);
list($key, $column) = explode('.', $keyAndColumn);

$this->relationColumns[$key][] = $column;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ private function appendOrderBy($order)

private function setGroupBy($groups)
{
$this->groupBy = explode(',', $groups);
$this->groupBy = array_filter(explode(',', $groups));
}

private function setLimit($limit)
Expand All @@ -223,14 +223,14 @@ private function addWhereToQuery($where)
return $this->applyCustomFilter($key, $operator, $value);
}

if (! $this->hasColumn($key)) {
if (! $this->hasTableColumn($key)) {
throw new UnknownColumnException("Unknown column '{$key}'");
}

$this->query->where($key, $operator, $value);
}

private function addOrderByToQuery($order)
private function addOrderByToQuery(array $order)
{
extract($order);

Expand Down Expand Up @@ -269,7 +269,7 @@ private function hasRelationColumns()
return (count($this->relationColumns) > 0);
}

private function hasColumn($column)
private function hasTableColumn($column)
{
return (Schema::hasColumn($this->model->getTable(), $column));
}
Expand Down
15 changes: 0 additions & 15 deletions src/UriParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,6 @@ public function __construct(Request $request)
}
}

public function pattern()
{
return $this->pattern;
}

public function queryUri()
{
return $this->queryUri;
}

public function queryParameters()
{
return $this->queryParameters;
}

public function queryParameter($key)
{
$keys = array_pluck($this->queryParameters, 'key');
Expand Down

0 comments on commit bba71cd

Please sign in to comment.