rspec/rules/S5857/php/rule.adoc

44 lines
672 B
Plaintext
Raw Normal View History

== Why is this an issue?
include::../description.adoc[]
=== Noncompliant code example
2022-02-04 17:28:24 +01:00
[source,php]
----
/<.+?>/
/".*?"/
----
=== Compliant solution
2022-02-04 17:28:24 +01:00
[source,php]
----
/<[^>]++>/
/"[^"]*+"/
----
or
2022-02-04 17:28:24 +01:00
[source,php]
----
/<[^>]+>/
/"[^"]*"/
----
=== Exceptions
This rule only applies in cases where the reluctant quantifier can easily be replaced with a negated character class. That means the repetition has to be terminated by a single character or character class. Patterns such as the following, where the alternatives without reluctant quantifiers are more complicated, are therefore not subject to this rule:
[source,php]
----
/<!--.*?-->/
-/\*.*?\*/-
----