Skip to content

Commit

Permalink
Added support for index by and changing selection set
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeniy Efimov authored and Evgeniy Efimov committed Apr 4, 2019
1 parent 2fcfef3 commit 923fb90
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
27 changes: 13 additions & 14 deletions src/Query/AbstractSelectionSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Doctrine\ORM\QueryBuilder;

/**
* Class AbstractSelectionSet
* Class AbstractSelectionSet.
*/
abstract class AbstractSelectionSet implements QueryModifier
{
Expand Down Expand Up @@ -36,21 +36,11 @@ public function __construct($fields, $dqlAlias = null)
}

/**
* Modify selection set in given query builder
*
* @param string[] $fields Prepared set of fields
* @param QueryBuilder $qb Query builder object
*
* @return mixed
*/
abstract protected function modifySelection(array $fields, QueryBuilder $qb);

/**
* @inheritDoc
* {@inheritdoc}
*/
final public function modify(QueryBuilder $qb, $dqlAlias)
{
if ($this->dqlAlias !== null) {
if (null !== $this->dqlAlias) {
$dqlAlias = $this->dqlAlias;
}

Expand All @@ -59,6 +49,15 @@ final public function modify(QueryBuilder $qb, $dqlAlias)
$this->modifySelection($fields, $qb);
}

/**
* Modify selection set in given query builder.
*
* @param string[] $fields Prepared set of fields
* @param QueryBuilder $qb Query builder object
*
* @return mixed
*/
abstract protected function modifySelection(array $fields, QueryBuilder $qb);

/**
* Return fields selection.
Expand All @@ -75,7 +74,7 @@ private function getSelection($dqlAlias)
$fieldName = $isAliased ? $k : $v;

list($fieldAlias, $fieldName) = explode('.', $fieldName, 2) + [null, null];
if ($fieldName === null) {
if (null === $fieldName) {
$fieldName = $fieldAlias;
$fieldAlias = $dqlAlias;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Query/AddSelectionSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class AddSelectionSet extends AbstractSelectionSet
{
/**
* @inheritDoc
* {@inheritdoc}
*/
protected function modifySelection(array $fields, QueryBuilder $qb)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Query/IndexBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct($field, $dqlAlias = null)
*/
public function modify(QueryBuilder $qb, $dqlAlias)
{
if ($this->dqlAlias !== null) {
if (null !== $this->dqlAlias) {
$dqlAlias = $this->dqlAlias;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Query/SelectionSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class SelectionSet extends AbstractSelectionSet
{
/**
* @inheritDoc
* {@inheritdoc}
*/
protected function modifySelection(array $fields, QueryBuilder $qb)
{
Expand Down
1 change: 1 addition & 0 deletions tests/Query/IndexBySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class IndexBySpec extends ObjectBehavior
{
private $field = 'the_field';

private $alias = 'f';

public function let()
Expand Down

0 comments on commit 923fb90

Please sign in to comment.