rspec/rules/S1125/php/rule.adoc

52 lines
1.1 KiB
Plaintext
Raw Normal View History

2023-10-13 13:50:06 +02:00
:true: true
:false: false
:ops: !, &&, ||, ==, !=
== Why is this an issue?
include::../description.adoc[]
2023-12-22 10:07:51 +01:00
=== Exceptions
The use of literal booleans in comparisons which use identity operators (`===` and `!==`) are ignored.
== How to fix it
include::../how-to-fix-it.adoc[]
2023-10-13 13:50:06 +02:00
=== Code examples
2023-10-13 13:50:06 +02:00
==== Noncompliant code example
[source,php,diff-id=1,diff-type=noncompliant]
----
if ($booleanVariable == true) { /* ... */ }
if ($booleanVariable != true) { /* ... */ }
if ($booleanVariable || false) { /* ... */ }
doSomething(!false);
----
2023-10-13 13:50:06 +02:00
==== Compliant solution
2023-10-13 13:50:06 +02:00
[source,php,diff-id=1,diff-type=compliant]
----
if ($booleanVariable) { /* ... */ }
if (!$booleanVariable) { /* ... */ }
if ($booleanVariable) { /* ... */ }
doSomething(true);
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
=== on 4 May 2020, 13:31:08 Pierre-Yves Nicolas wrote:
In PHP, this rule should not apply to the operands of ternary operators, see SONARPHP-906.
endif::env-github,rspecator-view[]