Last active
February 20, 2020 15:40
-
-
Save akash-coded/ce21c29c86cddc3e592e289a72527c22 to your computer and use it in GitHub Desktop.
Redundant Boolean literals should be removed from expressions to improve readability and remove code smells.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Noncompliant Code Example | |
if ($booleanVariable == true) { /* ... */ } | |
if ($booleanVariable != true) { /* ... */ } | |
if ($booleanVariable || false) { /* ... */ } | |
doSomething(!false); | |
$booleanVariable = condition ? true : exp; | |
$booleanVariable = condition ? false : exp; | |
$booleanVariable = condition ? exp : true; | |
$booleanVariable = condition ? exp : false; | |
// Compliant Solution | |
if ($booleanVariable) { /* ... */ } | |
if (!$booleanVariable) { /* ... */ } | |
if ($booleanVariable) { /* ... */ } | |
doSomething(true); | |
$booleanVariable = condition || exp; | |
$booleanVariable = !condition && exp; | |
$booleanVariable = !condition || exp; | |
$booleanVariable = condition && exp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment