]> BookStack Code Mirror - bookstack/blobdiff - app/Search/SearchOptionSet.php
Enhance changelog input to textarea with character counter
[bookstack] / app / Search / SearchOptionSet.php
index 467dc9f5ae1d7ff4dac84f56ff6d33d94274d157..bd5e5a5b222671a737f620ba9513fdf219655c25 100644 (file)
@@ -4,10 +4,13 @@ namespace BookStack\Search;
 
 use BookStack\Search\Options\SearchOption;
 
+/**
+ * @template T of SearchOption
+ */
 class SearchOptionSet
 {
     /**
-     * @var SearchOption[]
+     * @var T[]
      */
     protected array $options = [];
 
@@ -52,7 +55,7 @@ class SearchOptionSet
     }
 
     /**
-     * @return SearchOption[]
+     * @return T[]
      */
     public function all(): array
     {
@@ -60,10 +63,20 @@ class SearchOptionSet
     }
 
     /**
-     * @return SearchOption[]
+     * @return self<T>
      */
-    public function negated(): array
+    public function negated(): self
     {
-        return array_values(array_filter($this->options, fn (SearchOption $option) => $option->negated));
+        $values = array_values(array_filter($this->options, fn (SearchOption $option) => $option->negated));
+        return new self($values);
+    }
+
+    /**
+     * @return self<T>
+     */
+    public function nonNegated(): self
+    {
+        $values = array_values(array_filter($this->options, fn (SearchOption $option) => !$option->negated));
+        return new self($values);
     }
 }