rspec/rules/S2761/php/rule.adoc

34 lines
736 B
Plaintext
Raw Normal View History

== Why is this an issue?
The repetition of a prefix operator (``++!++``, or ``++~++``) is usually a typo. The second operator invalidates the first one:
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2020-06-30 12:48:07 +02:00
----
$a = false;
$b = ~~$a; // Noncompliant: equivalent to "$a"
2020-06-30 12:48:07 +02:00
----
While calling ``++!++`` twice is equivalent to calling the `boolval()` function, the latter increases the code readability, so it should be preferred.
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2020-06-30 12:48:07 +02:00
----
$a = 0;
$b = !!$a; // Noncompliant: equivalent to "boolval($a)"
2020-06-30 12:48:07 +02:00
----
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[]