From fd46c0a39d001a7e6acaa355f299fd1fccf1d790 Mon Sep 17 00:00:00 2001 From: Jonas Wielage Date: Tue, 3 Dec 2024 13:56:35 +0100 Subject: [PATCH] SONARPHP-1530 S1125 should raise an issue when a boolean literal is used in a xor expression (#1334) --- .../org/sonar/php/checks/BooleanEqualityComparisonCheck.java | 3 ++- .../test/resources/checks/BooleanEqualityComparisonCheck.php | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/php-checks/src/main/java/org/sonar/php/checks/BooleanEqualityComparisonCheck.java b/php-checks/src/main/java/org/sonar/php/checks/BooleanEqualityComparisonCheck.java index 66ffe2da96..13bce62172 100644 --- a/php-checks/src/main/java/org/sonar/php/checks/BooleanEqualityComparisonCheck.java +++ b/php-checks/src/main/java/org/sonar/php/checks/BooleanEqualityComparisonCheck.java @@ -36,7 +36,8 @@ public class BooleanEqualityComparisonCheck extends PHPVisitorCheck { Kind.ALTERNATIVE_CONDITIONAL_AND, Kind.EQUAL_TO, Kind.NOT_EQUAL_TO, - Kind.ALTERNATIVE_NOT_EQUAL_TO + Kind.ALTERNATIVE_NOT_EQUAL_TO, + Kind.ALTERNATIVE_CONDITIONAL_XOR }; @Override diff --git a/php-checks/src/test/resources/checks/BooleanEqualityComparisonCheck.php b/php-checks/src/test/resources/checks/BooleanEqualityComparisonCheck.php index c6eef2aeed..2179147b4b 100644 --- a/php-checks/src/test/resources/checks/BooleanEqualityComparisonCheck.php +++ b/php-checks/src/test/resources/checks/BooleanEqualityComparisonCheck.php @@ -18,6 +18,8 @@ || b || true; // Noncompliant (a || true) ? b : c; // Noncompliant +true xor a; // Noncompliant +$a xor false; // Noncompliant a === false; // OK - exception a === true; // OK - exception