rspec/rules/S6323/php/rule.adoc
Karim El Ouerghemmi ddb9c3332b
Add PHP to S6323 (#650)
Co-authored-by: Nils Werner <64034005+nils-werner-sonarsource@users.noreply.github.com>
2022-02-02 13:10:58 +00:00

39 lines
797 B
Plaintext

include::../description.adoc[]
== Noncompliant Code Example
----
preg_match("/Jack|Peter|/", "John"); // Noncompliant - returns 1
preg_match("/Jack||Peter/", "John"); // Noncompliant - returns 1
----
== Compliant Solution
----
preg_match("/Jack|Peter/", "John"); // returns 0
----
== Exceptions
One could use an empty alternation to make a regular expression group optional. Rule will not report on such cases.
----
preg_match("/mandatory(-optional|)/", "mandatory"); // returns 1
preg_match("/mandatory(-optional|)/", "mandatory-optional"); // returns 1
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
== Message
Remove this empty alternative.
== Highlighting
The | should be highlighted.
'''
endif::env-github,rspecator-view[]