Skip to content

Commit

Permalink
Feat: Require comparisons to be strict (fixes #90)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Apr 26, 2024
1 parent cde08b1 commit bf2f540
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ecs.php
Expand Up @@ -125,6 +125,7 @@
use PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer;
use PhpCsFixer\Fixer\Semicolon\SpaceAfterSemicolonFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
Expand Down Expand Up @@ -365,6 +366,8 @@
DeclareStrictTypesFixer::class,
// Functions should be used with `$strict` param set to `true`
StrictParamFixer::class,
// Comparisons should be strict, `===` or `!==` must be used for comparisons
StrictComparisonFixer::class,
// Convert double quotes to single quotes for simple strings
SingleQuoteFixer::class,
// Remove extra spaces in a nullable typehint
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Fixtures/Basic.correct.php.inc
Expand Up @@ -14,8 +14,8 @@ class Basic
$lambdaWithUnusedImport = function () { return 'foo'; };
// NoUselessSprintfFixer
$uselessSprintf = 'bar';
// SingleSpaceAfterConstructFixer
if ($a == $b) {
// SingleSpaceAfterConstructFixer, StrictComparisonFixer
if ($a === $b || $bazLength !== 3) {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Fixtures/Basic.wrong.php.inc
Expand Up @@ -13,8 +13,8 @@ class Basic
$lambdaWithUnusedImport = function () use ($fooBar) { return 'foo'; };
// NoUselessSprintfFixer
$uselessSprintf = sprintf('bar');
// SingleSpaceAfterConstructFixer
if ($a == $b) { return true; }
// SingleSpaceAfterConstructFixer, StrictComparisonFixer
if ($a == $b || $bazLength != 3) { return true; }
return false; // BlankLineBeforeStatementFixer
}

Expand Down

0 comments on commit bf2f540

Please sign in to comment.