Skip to content

Commit

Permalink
Remove shouldUseCollections function
Browse files Browse the repository at this point in the history
Remove shouldUseCollections function which checks Laravel version > 5.3, it was introduced to support version 5.3 in #925
  • Loading branch information
divine committed Mar 4, 2020
1 parent 20754f1 commit 37a0aa7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,3 +4,4 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
### Removed
- EmbedsOne and EmbedsMany relations by [@divine](https://github.com/divine).
- shouldUseCollections function by [@divine](https://github.com/divine).
32 changes: 5 additions & 27 deletions src/Jenssegers/Mongodb/Query/Builder.php
Expand Up @@ -115,12 +115,6 @@ class Builder extends BaseBuilder
'>=' => '$gte',
];

/**
* Check if we need to return Collections instead of plain arrays (laravel >= 5.3 )
* @var boolean
*/
protected $useCollections;

/**
* @inheritdoc
*/
Expand All @@ -129,22 +123,6 @@ public function __construct(Connection $connection, Processor $processor)
$this->grammar = new Grammar;
$this->connection = $connection;
$this->processor = $processor;
$this->useCollections = $this->shouldUseCollections();
}

/**
* Returns true if Laravel or Lumen >= 5.3
* @return bool
*/
protected function shouldUseCollections()
{
if (function_exists('app')) {
$version = app()->version();
$version = filter_var(explode(')', $version)[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); // lumen
return version_compare($version, '5.3', '>=');
}

return true;
}

/**
Expand Down Expand Up @@ -285,7 +263,7 @@ public function getFresh($columns = [])
'aggregate' => $totalResults
]
];
return $this->useCollections ? new Collection($results) : $results;
return new Collection($results);
} elseif ($function == 'count') {
// Translate count into sum.
$group['aggregate'] = ['$sum' => 1];
Expand Down Expand Up @@ -342,7 +320,7 @@ public function getFresh($columns = [])
$results = iterator_to_array($this->collection->aggregate($pipeline, $options));

// Return results
return $this->useCollections ? new Collection($results) : $results;
return new Collection($results);
} // Distinct query
elseif ($this->distinct) {
// Return distinct results directly
Expand All @@ -355,7 +333,7 @@ public function getFresh($columns = [])
$result = $this->collection->distinct($column);
}

return $this->useCollections ? new Collection($result) : $result;
return new Collection($result);
} // Normal query
else {
$columns = [];
Expand Down Expand Up @@ -404,7 +382,7 @@ public function getFresh($columns = [])

// Return results as an array with numeric keys
$results = iterator_to_array($cursor, false);
return $this->useCollections ? new Collection($results) : $results;
return new Collection($results);
}
}

Expand Down Expand Up @@ -659,7 +637,7 @@ public function pluck($column, $key = null)
}

$p = Arr::pluck($results, $column, $key);
return $this->useCollections ? new Collection($p) : $p;
return new Collection($p);
}

/**
Expand Down

0 comments on commit 37a0aa7

Please sign in to comment.