From adc9b6fedb0fdc43ee264a511e88022cbfb0003e Mon Sep 17 00:00:00 2001 From: Asis Pattisahusiwa <79239132+asispts@users.noreply.github.com> Date: Fri, 3 Nov 2023 19:40:30 +0700 Subject: [PATCH] Use static closure if possible (#19) --- ptscs/ruleset.xml | 1 + .../Slevomat/Functions/StaticClosureTest.php | 23 +++++++++++++++++++ .../Functions/_data/StaticClosure.php.fixed | 13 +++++++++++ .../Functions/_data/StaticClosure.php.inc | 13 +++++++++++ ...InheritedVariablePassedToClosure.php.fixed | 2 +- ...edInheritedVariablePassedToClosure.php.inc | 2 +- .../Unsolved/_data/ScopeIndent.php.fixed | 2 +- .../Sniffs/Unsolved/_data/ScopeIndent.php.inc | 2 +- 8 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 tests/Sniffs/Slevomat/Functions/StaticClosureTest.php create mode 100644 tests/Sniffs/Slevomat/Functions/_data/StaticClosure.php.fixed create mode 100644 tests/Sniffs/Slevomat/Functions/_data/StaticClosure.php.inc diff --git a/ptscs/ruleset.xml b/ptscs/ruleset.xml index 7675c2a..fb30393 100644 --- a/ptscs/ruleset.xml +++ b/ptscs/ruleset.xml @@ -193,6 +193,7 @@ + diff --git a/tests/Sniffs/Slevomat/Functions/StaticClosureTest.php b/tests/Sniffs/Slevomat/Functions/StaticClosureTest.php new file mode 100644 index 0000000..760f348 --- /dev/null +++ b/tests/Sniffs/Slevomat/Functions/StaticClosureTest.php @@ -0,0 +1,23 @@ +appendExclude('Squiz.Classes.ClassFileName.NoMatch'); + } + + public static function provideTestData(): Iterator + { + yield[ + [new ErrorData(9, 'SlevomatCodingStandard.Functions.StaticClosure.ClosureNotStatic')], + ]; + } +} diff --git a/tests/Sniffs/Slevomat/Functions/_data/StaticClosure.php.fixed b/tests/Sniffs/Slevomat/Functions/_data/StaticClosure.php.fixed new file mode 100644 index 0000000..c40f8da --- /dev/null +++ b/tests/Sniffs/Slevomat/Functions/_data/StaticClosure.php.fixed @@ -0,0 +1,13 @@ +callback(function () { +$this->callback(static function () { if (true) { } diff --git a/tests/Sniffs/Unsolved/_data/ScopeIndent.php.inc b/tests/Sniffs/Unsolved/_data/ScopeIndent.php.inc index 160b640..9ec8ecc 100644 --- a/tests/Sniffs/Unsolved/_data/ScopeIndent.php.inc +++ b/tests/Sniffs/Unsolved/_data/ScopeIndent.php.inc @@ -1,6 +1,6 @@ callback(function () { +$this->callback(static function () { if (true) { }