diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..0e40fe8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+
+# Default ignored files
+/workspace.xml
\ No newline at end of file
diff --git a/.idea/array-query.iml b/.idea/array-query.iml
new file mode 100644
index 0000000..7efac6d
--- /dev/null
+++ b/.idea/array-query.iml
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..28a804d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..d1dff96
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/php.xml b/.idea/php.xml
new file mode 100644
index 0000000..e8610d2
--- /dev/null
+++ b/.idea/php.xml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Exceptions/EmptyArrayException.php b/src/Exceptions/EmptyArrayException.php
deleted file mode 100644
index 521e903..0000000
--- a/src/Exceptions/EmptyArrayException.php
+++ /dev/null
@@ -1,15 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace ArrayQuery\Exceptions;
-
-class EmptyArrayException extends \Exception
-{
-}
diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php
index 14e7e2f..4744cc7 100644
--- a/src/QueryBuilder.php
+++ b/src/QueryBuilder.php
@@ -10,18 +10,15 @@
namespace ArrayQuery;
-use ArrayQuery\Exceptions\EmptyArrayException;
-use ArrayQuery\Exceptions\InvalidArrayException;
use ArrayQuery\Exceptions\NotConsistentDataException;
use ArrayQuery\Exceptions\NotExistingElementException;
use ArrayQuery\Exceptions\NotValidCriterionOperatorException;
-use ArrayQuery\Exceptions\NotValidKeyElementInArrayException;
use ArrayQuery\Exceptions\NotValidLimitsOfArrayException;
use ArrayQuery\Exceptions\NotValidSortingOperatorException;
use ArrayQuery\Filters\CriterionFilter;
use ArrayQuery\Filters\JoinFilter;
-use ArrayQuery\Filters\SortingFilter;
use ArrayQuery\Filters\LimitFilter;
+use ArrayQuery\Filters\SortingFilter;
use ArrayQuery\Helpers\ArrayHelper;
use ArrayQuery\Helpers\ConsistencyChecker;
@@ -54,7 +51,10 @@ class QueryBuilder
/**
* QueryBuilder constructor.
+ *
* @param array $array
+ *
+ * @throws NotConsistentDataException
*/
public function __construct(array $array)
{
@@ -63,7 +63,9 @@ public function __construct(array $array)
/**
* @param array $array
+ *
* @return static
+ * @throws NotConsistentDataException
*/
public static function create(array $array)
{
@@ -72,7 +74,8 @@ public static function create(array $array)
/**
* @param array $array
- * @throws EmptyArrayException
+ *
+ * @return array
* @throws NotConsistentDataException
*/
private function setArray(array $array)
@@ -237,6 +240,10 @@ public function join($array, $arrayName, $parentKey, $foreignKey)
*/
public function getResults()
{
+ if(empty($this->array)){
+ return [];
+ }
+
$results = $this->applySortingFilter($this->applyLimitFilter($this->applyCriteriaFilter($this->applyJoinFilter())));
return array_map([ArrayHelper::class, 'convertToPlainArray'], $results);
@@ -317,7 +324,7 @@ private function applyJoinFilter()
*/
private function applyCriteriaFilter(array $array)
{
- if (count($this->criteria) === 0) {
+ if (empty($this->criteria) or count($this->criteria) === 0) {
return $array;
}
diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php
index c6d36de..6315c54 100644
--- a/tests/QueryBuilderTest.php
+++ b/tests/QueryBuilderTest.php
@@ -30,12 +30,12 @@ public function setUp()
/**
* @test
- * @expectedException \ArrayQuery\Exceptions\EmptyArrayException
- * @expectedExceptionMessage Empty array provided.
*/
- public function it_throws_EmptyCollectionException_if_an_empty_array_is_provided()
+ public function it_return_a_void_array_if_an_empty_array_is_provided()
{
- QueryBuilder::create([]);
+ $qb = QueryBuilder::create([]);
+
+ $this->assertEquals([], $qb->getResults());
}
/**
@@ -195,7 +195,6 @@ public function it_should_get_results_with_no_criteria_applied()
{
foreach ($this->usersArrays as $array) {
$qb = QueryBuilder::create($array);
-
$this->assertCount(10, $qb->getResults());
}
}