Skip to content

Commit bf2f540

Browse files
committed
Feat: Require comparisons to be strict (fixes #90)
1 parent cde08b1 commit bf2f540

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

ecs.php

+3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
use PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer;
126126
use PhpCsFixer\Fixer\Semicolon\SpaceAfterSemicolonFixer;
127127
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
128+
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
128129
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
129130
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
130131
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
@@ -365,6 +366,8 @@
365366
DeclareStrictTypesFixer::class,
366367
// Functions should be used with `$strict` param set to `true`
367368
StrictParamFixer::class,
369+
// Comparisons should be strict, `===` or `!==` must be used for comparisons
370+
StrictComparisonFixer::class,
368371
// Convert double quotes to single quotes for simple strings
369372
SingleQuoteFixer::class,
370373
// Remove extra spaces in a nullable typehint

tests/Integration/Fixtures/Basic.correct.php.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class Basic
1414
$lambdaWithUnusedImport = function () { return 'foo'; };
1515
// NoUselessSprintfFixer
1616
$uselessSprintf = 'bar';
17-
// SingleSpaceAfterConstructFixer
18-
if ($a == $b) {
17+
// SingleSpaceAfterConstructFixer, StrictComparisonFixer
18+
if ($a === $b || $bazLength !== 3) {
1919
return true;
2020
}
2121

tests/Integration/Fixtures/Basic.wrong.php.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class Basic
1313
$lambdaWithUnusedImport = function () use ($fooBar) { return 'foo'; };
1414
// NoUselessSprintfFixer
1515
$uselessSprintf = sprintf('bar');
16-
// SingleSpaceAfterConstructFixer
17-
if ($a == $b) { return true; }
16+
// SingleSpaceAfterConstructFixer, StrictComparisonFixer
17+
if ($a == $b || $bazLength != 3) { return true; }
1818
return false; // BlankLineBeforeStatementFixer
1919
}
2020

0 commit comments

Comments
 (0)