rspec/rules/S2010/php/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

61 lines
1.5 KiB
Plaintext

== Why is this an issue?
Boolean operators are used to combine conditional statements based on their value.
In PHP, there are two different sets of operators to use for AND and OR:
* ``++&&++`` / ``++||++``
* ``++and++`` / ``++or++``
The difference between these sets is the precedence, which specifies how "tightly" two expressions are bound together.
Because ``++and++`` / ``++or++`` have a lower precedence than almost any other operator, using them instead of ``++&&++`` / ``++||++`` may not have the result you expect.
=== Noncompliant code example
In both cases, the assignment has a higher precedence over the boolean operation.
[source,php,diff-id=1,diff-type=noncompliant]
----
$resultAnd = true and false; // Noncompliant: $resultAnd == true
$resultOr = false or true; // Noncompliant: $resultOr == false
----
=== Compliant solution
[source,php,diff-id=1,diff-type=compliant]
----
$resultAnd = true && false; // $resultAnd == false
$resultOr = false || true; // $resultOr == true
----
== Resources
=== Documentation
* https://www.php.net/manual/en/language.operators.logical.php[PHP Manual - Logical Operators]
* https://www.php.net/manual/en/language.operators.precedence.php[PHP Manual - Operator Precedence]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Replace "xxx" with "yy".
'''
== Comments And Links
(visible only on this page)
=== is related to: S3659
endif::env-github,rspecator-view[]