]> BookStack Code Mirror - bookstack/blobdiff - app/Search/SearchOptionSet.php
Merge pull request #5917 from BookStackApp/copy_references
[bookstack] / app / Search / SearchOptionSet.php
index 467dc9f5ae1d7ff4dac84f56ff6d33d94274d157..844d145e6fcc39f0085435b81c706345d4226924 100644 (file)
@@ -4,13 +4,19 @@ namespace BookStack\Search;
 
 use BookStack\Search\Options\SearchOption;
 
+/**
+ * @template T of SearchOption
+ */
 class SearchOptionSet
 {
     /**
-     * @var SearchOption[]
+     * @var T[]
      */
     protected array $options = [];
 
+    /**
+     * @param T[] $options
+     */
     public function __construct(array $options = [])
     {
         $this->options = $options;
@@ -52,7 +58,7 @@ class SearchOptionSet
     }
 
     /**
-     * @return SearchOption[]
+     * @return T[]
      */
     public function all(): array
     {
@@ -60,10 +66,20 @@ class SearchOptionSet
     }
 
     /**
-     * @return SearchOption[]
+     * @return self<T>
+     */
+    public function negated(): self
+    {
+        $values = array_values(array_filter($this->options, fn (SearchOption $option) => $option->negated));
+        return new self($values);
+    }
+
+    /**
+     * @return self<T>
      */
-    public function negated(): array
+    public function nonNegated(): 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);
     }
 }