rspec/rules/S2010/php/rule.adoc

41 lines
937 B
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
PHP has two sets of logical operators: ``++&&++`` / ``++||++``, and ``++and++`` / ``++or++``. The difference between the sets is precedence. 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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2021-04-28 16:49:39 +02:00
----
$have_time = true;
$have_money = false;
$take_vacation = $have_time and $have_money; // Noncompliant. $take_vacation == true.
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2021-04-28 16:49:39 +02:00
----
$have_time = true;
$have_money = false;
$take_vacation = $have_time && $have_money; // $take_vacation == false.
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]