Skip to content

Commit

Permalink
Disallow loose comparison operator (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
asispts committed Nov 10, 2023
1 parent f735764 commit 27180c7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions ptscs/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation" />
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation" />

<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators" />

<!--++++++++++++++++++++++++++++++++++++
Code analysis
Expand Down
19 changes: 19 additions & 0 deletions tests/Sniffs/Slevomat/Operators/DisallowEqualOperatorsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);

namespace Ptscs\Tests\Sniffs\Slevomat\Operators;

use Iterator;
use Ptscs\Tests\SniffTestCase;
use Ptscs\Tests\Utils\ErrorData;

final class DisallowEqualOperatorsTest extends SniffTestCase
{
public static function provideTestData(): Iterator
{
yield[
[
new ErrorData(5, 'SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedEqualOperator'),
],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php declare(strict_types=1);

$a = null;

if ($a === '' || $a !== null) {
$a = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php declare(strict_types=1);

$a = null;

if ($a == '' || $a != null) {
$a = 0;
}

0 comments on commit 27180c7

Please sign in to comment.