@@ -217,7 +217,7 @@ public function getRulesAssoc($searchPattern = null): array
217217 * @param Rule|string|null $searchPattern
218218 * `Rule` to remove.
219219 * Passing a `string` or `null` is deprecated in version 8.9.0, and will no longer work from v9.0.
220- * Use `removeMatchingRules()` instead.
220+ * Use `removeMatchingRules()` or `removeAllRules()` instead.
221221 */
222222 public function removeRule ($ searchPattern ): void
223223 {
@@ -231,27 +231,30 @@ public function removeRule($searchPattern): void
231231 unset($ this ->rules [$ nameOfPropertyToRemove ][$ key ]);
232232 }
233233 }
234- } else {
234+ } elseif ( $ searchPattern !== null ) {
235235 $ this ->removeMatchingRules ($ searchPattern );
236+ } else {
237+ $ this ->removeAllRules ();
236238 }
237239 }
238240
239241 /**
240242 * Removes rules by property name or search pattern.
241243 *
242- * @param string|null $searchPattern
243- * pattern to remove. If null, all rules are removed. If the pattern ends in a dash,
244+ * @param string $searchPattern
245+ * pattern to remove.
246+ * If the pattern ends in a dash,
244247 * all rules starting with the pattern are removed as well as one matching the pattern with the dash
245248 * excluded.
246249 */
247- public function removeMatchingRules (? string $ searchPattern ): void
250+ public function removeMatchingRules (string $ searchPattern ): void
248251 {
249252 foreach ($ this ->rules as $ propertyName => $ rules ) {
250- // Either no search rule is given or the search rule matches the found rule exactly
253+ // Either the search rule matches the found rule exactly
251254 // or the search rule ends in “-” and the found rule starts with the search rule or equals it
252255 // (without the trailing dash).
253256 if (
254- $ searchPattern === null || $ propertyName === $ searchPattern
257+ $ propertyName === $ searchPattern
255258 || (\strrpos ($ searchPattern , '- ' ) === \strlen ($ searchPattern ) - \strlen ('- ' )
256259 && (\strpos ($ propertyName , $ searchPattern ) === 0
257260 || $ propertyName === \substr ($ searchPattern , 0 , -1 )))
@@ -261,6 +264,11 @@ public function removeMatchingRules(?string $searchPattern): void
261264 }
262265 }
263266
267+ public function removeAllRules (): void
268+ {
269+ $ this ->rules = [];
270+ }
271+
264272 protected function renderRules (OutputFormat $ outputFormat ): string
265273 {
266274 $ result = '' ;
0 commit comments