rspec/rules/S1121/php/rule.adoc

65 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2020-06-30 12:47:33 +02:00
include::../description.adoc[]
=== Exceptions
This rule ignores assignments in conditions of `while` statements and assignments enclosed in relational expressions.
2020-06-30 12:47:33 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2020-06-30 12:47:33 +02:00
----
while (($line = next_line()) != NULL) {...}
while ($line = next_line()) {...}
----
== How to fix it
include::../how-to-fix-it.adoc[]
=== Code examples
==== Noncompliant code example
[source,php,diff-id=1,diff-type=noncompliant]
----
if (($val = value()) && check()) { // Noncompliant
2020-06-30 12:47:33 +02:00
}
----
==== Compliant solution
2020-06-30 12:47:33 +02:00
[source,php,diff-id=1,diff-type=compliant]
2020-06-30 12:47:33 +02:00
----
$val = value();
if ($val && check()) {
}
----
or
[source,php,diff-id=1,diff-type=compliant]
2020-06-30 12:47:33 +02:00
----
if ($val == value() && check()) { // Original intention might have been to use equality operator and not assignment
2020-06-30 12:47:33 +02:00
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]