diff --git a/src/Query.php b/src/Query.php index d7f8418..bfff4c5 100644 --- a/src/Query.php +++ b/src/Query.php @@ -141,15 +141,18 @@ public function get(string|int $key): mixed /** * @param string $key * @param string|mixed[] $value + * @return self * @throws Exception */ - public function set(string $key, string|array $value): void + public function set(string $key, string|array $value): self { $this->initArray(); $this->array[$key] = is_array($value) ? $this->newWithSameSettings($value) : $value; $this->setDirty(); + + return $this; } /** @@ -184,7 +187,7 @@ public function isScalar(int|string $key): bool * @param string|mixed[] $value * @throws Exception */ - public function appendTo(string $key, string|array $value): void + public function appendTo(string $key, string|array $value): self { $currentValue = $this->get($key); @@ -195,6 +198,8 @@ public function appendTo(string $key, string|array $value): void $this->array[$key] = $this->newWithSameSettings($newQueryArray); $this->setDirty(); + + return $this; } /** @@ -222,7 +227,7 @@ public function last(?string $key = null): mixed /** * @throws Exception */ - public function remove(string $key): void + public function remove(string $key): self { $this->initArray(); @@ -231,12 +236,14 @@ public function remove(string $key): void $this->setDirty(); } + + return $this; } /** * @throws Exception */ - public function removeValueFrom(string $fromKey, mixed $removeValue): void + public function removeValueFrom(string $fromKey, mixed $removeValue): self { $fromKeyValue = $this->get($fromKey); @@ -255,15 +262,17 @@ public function removeValueFrom(string $fromKey, mixed $removeValue): void $fromKeyValue->array = array_values($fromKeyValue->array); } } + + return $this; } /** * @throws Exception */ - public function boolToInt(): void + public function boolToInt(): self { if ($this->boolToInt) { - return; + return $this; } $this->boolToInt = true; @@ -275,15 +284,17 @@ public function boolToInt(): void } $this->setDirty(); + + return $this; } /** * @throws Exception */ - public function boolToString(): void + public function boolToString(): self { if (!$this->boolToInt) { - return; + return $this; } $this->boolToInt = false; @@ -295,15 +306,17 @@ public function boolToString(): void } $this->setDirty(); + + return $this; } /** * @throws Exception */ - public function separator(string $separator): void + public function separator(string $separator): self { if ($this->separator === $separator) { - return; + return $this; } $this->separator = $separator; @@ -315,16 +328,18 @@ public function separator(string $separator): void } $this->setDirty(); + + return $this; } /** * @throws Exception */ - public function spaceCharacterEncoding(int $spaceCharacterEncodingConst): void + public function spaceCharacterEncoding(int $spaceCharacterEncodingConst): self { if (in_array($spaceCharacterEncodingConst, [PHP_QUERY_RFC1738, PHP_QUERY_RFC3986], true)) { if ($spaceCharacterEncodingConst === $this->spaceCharacterEncoding) { - return; + return $this; } $this->spaceCharacterEncoding = $spaceCharacterEncodingConst; @@ -337,22 +352,24 @@ public function spaceCharacterEncoding(int $spaceCharacterEncodingConst): void $this->setDirty(); } + + return $this; } /** * @throws Exception */ - public function spaceCharacterPlus(): void + public function spaceCharacterPlus(): self { - $this->spaceCharacterEncoding(PHP_QUERY_RFC1738); + return $this->spaceCharacterEncoding(PHP_QUERY_RFC1738); } /** * @throws Exception */ - public function spaceCharacterPercentTwenty(): void + public function spaceCharacterPercentTwenty(): self { - $this->spaceCharacterEncoding(PHP_QUERY_RFC3986); + return $this->spaceCharacterEncoding(PHP_QUERY_RFC3986); } /**