]> BookStack Code Mirror - bookstack/blobdiff - app/Api/ListingResponseBuilder.php
respective book and chapter structure added.
[bookstack] / app / Api / ListingResponseBuilder.php
index 6da92040b4cc4a40679fa46abe2a842b087397eb..44117bad9759e5108502485003c66fd3a599e96f 100644 (file)
@@ -2,24 +2,31 @@
 
 namespace BookStack\Api;
 
-use BookStack\Model;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Database\Eloquent\Model;
 use Illuminate\Http\JsonResponse;
 use Illuminate\Http\Request;
 
 class ListingResponseBuilder
 {
-    protected $query;
-    protected $request;
-    protected $fields;
+    protected Builder $query;
+    protected Request $request;
+
+    /**
+     * @var string[]
+     */
+    protected array $fields;
 
     /**
      * @var array<callable>
      */
-    protected $resultModifiers = [];
+    protected array $resultModifiers = [];
 
-    protected $filterOperators = [
+    /**
+     * @var array<string, string>
+     */
+    protected array $filterOperators = [
         'eq'   => '=',
         'ne'   => '!=',
         'gt'   => '>',
@@ -48,7 +55,7 @@ class ListingResponseBuilder
         $filteredQuery = $this->filterQuery($this->query);
 
         $total = $filteredQuery->count();
-        $data = $this->fetchData($filteredQuery)->each(function($model) {
+        $data = $this->fetchData($filteredQuery)->each(function ($model) {
             foreach ($this->resultModifiers as $modifier) {
                 $modifier($model);
             }
@@ -61,10 +68,11 @@ class ListingResponseBuilder
     }
 
     /**
-     * Add a callback to modify each element of the results
-     * @param (callable(Model)) $modifier
+     * Add a callback to modify each element of the results.
+     *
+     * @param (callable(Model): void) $modifier
      */
-    public function modifyResults($modifier): void
+    public function modifyResults(callable $modifier): void
     {
         $this->resultModifiers[] = $modifier;
     }