From b5492a931a39bbce5a97a0028c55eee8d7cd9de1 Mon Sep 17 00:00:00 2001
From: Mantas <marc.mantas@gmail.com>
Date: Fri, 10 Jun 2016 14:16:32 +0300
Subject: [PATCH] added parameter trait to FieldSort

---
 src/Sort/FieldSort.php | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/src/Sort/FieldSort.php b/src/Sort/FieldSort.php
index 7389976..f11a445 100644
--- a/src/Sort/FieldSort.php
+++ b/src/Sort/FieldSort.php
@@ -12,12 +12,15 @@
 namespace ONGR\ElasticsearchDSL\Sort;
 
 use ONGR\ElasticsearchDSL\BuilderInterface;
+use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
  * Holds all the values required for basic sorting.
  */
 class FieldSort implements BuilderInterface
 {
+    use ParametersTrait;
+
     const ASC = 'asc';
     const DESC = 'desc';
 
@@ -31,11 +34,6 @@ class FieldSort implements BuilderInterface
      */
     private $order;
 
-    /**
-     * @var array
-     */
-    private $params;
-
     /**
      * @var BuilderInterface
      */
@@ -50,7 +48,7 @@ class FieldSort implements BuilderInterface
     {
         $this->field = $field;
         $this->order = $order;
-        $this->params = $params;
+        $this->setParameters($params);
     }
 
     /**
@@ -85,22 +83,15 @@ class FieldSort implements BuilderInterface
     public function toArray()
     {
         if ($this->order) {
-            $this->params['order'] = $this->order;
+            $this->addParameter('order', $this->order);
         }
 
         if ($this->nestedFilter) {
-            $fieldValues = array_merge(
-                $this->params,
-                [
-                    'nested_filter' => $this->nestedFilter->toArray(),
-                ]
-            );
-        } else {
-            $fieldValues = $this->params;
+            $this->addParameter('nested_filter', $this->nestedFilter->toArray());
         }
 
         $output = [
-            $this->field => empty($fieldValues) ? new \stdClass() : $fieldValues,
+            $this->field => !$this->getParameters() ? new \stdClass() : $this->getParameters(),
         ];
 
         return $output;
-- 
GitLab