Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Rule] The use of literal logical operators MUST be avoided #23

Closed
lenaorobei opened this issue Jan 30, 2019 · 1 comment
Closed
Assignees
Labels
accepted New rule is accepted new rule New feature implementation Progress: good first issue Issues is easy to get started with proposal New rule proposal

Comments

@lenaorobei
Copy link
Contributor

Rule

The use of literal logical operators (and, or) is discouraged. && and || should be used instead.

Reason

Operator precedence is different for and vs. && and or vs. ||.
It may cause unexpected behaviour:

$x = false || true;  // is ($x = (false || true)) => true
$x = false or true;  // is (($x = false) or true) => false
    
$x = true && false;  // is ($x = (true && false)) => false
$x = true and false; // is (($x = true) and false) => true

Please use the official documentation for more details.

Implementation

Add Squiz.Operators.ValidLogicalOperators to the ruleset.xml.

@lenaorobei lenaorobei added proposal New rule proposal need to discuss Rule requires discussion new rule New feature implementation labels Jan 30, 2019
@lenaorobei lenaorobei changed the title [New Rule] The use of literal logical operators is discouraged [New Rule] The use of literal logical operators MUST be avoided Jan 31, 2019
@lenaorobei lenaorobei added the accepted New rule is accepted label Feb 13, 2019
@lenaorobei lenaorobei added the Progress: good first issue Issues is easy to get started with label Feb 15, 2019
novikor pushed a commit to novikor/magento-coding-standard that referenced this issue Feb 15, 2019
…nto#23.

Added new rule: Squiz.Operators.ValidLogicalOperators
@lenaorobei lenaorobei removed the need to discuss Rule requires discussion label Feb 19, 2019
lenaorobei added a commit that referenced this issue Feb 19, 2019
…al-operators-MUST-be-avoided-23

[New Rule] The use of literal logical operators MUST be avoided #23.
@lenaorobei
Copy link
Contributor Author

Fixed #40

magento-devops-reposync-svc pushed a commit that referenced this issue Aug 23, 2021
…-coding-standard-223

[Imported] AC-957: Create unit test for Magento2\Html\HtmlDirectiveSniff check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted New rule is accepted new rule New feature implementation Progress: good first issue Issues is easy to get started with proposal New rule proposal
Projects
None yet
Development

No branches or pull requests

2 participants