diff --git a/.php_cs.dist b/.php_cs.dist index bacb0b2706..fbcc8106f0 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -26,6 +26,7 @@ return PhpCsFixer\Config::create() 'php_unit_test_class_requires_covers' => false, 'phpdoc_order' => true, 'phpdoc_types_order' => ['null_adjustment' => 'always_last'], + 'static_lambda' => true, 'ternary_to_null_coalescing' => true, 'visibility_required' => ['property', 'method', 'const'], 'void_return' => true, diff --git a/CHANGELOG.md b/CHANGELOG.md index 79847a1cba..e40cc94580 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added `symfony/deprecation-contracts` package to handle deprecations [#1823](https://github.com/ruflin/Elastica/pull/1823) * Added `list_syntax` CS rule [#1854](https://github.com/ruflin/Elastica/pull/1854) * Added `native_constant_invocation` CS rule [#1833](https://github.com/ruflin/Elastica/pull/1833) +* Added `static_lambda` CS rule [#1870](https://github.com/ruflin/Elastica/pull/1870) * Added `Elastica\Aggregation\DateRange::setTimezone()` [#1847](https://github.com/ruflin/Elastica/pull/1847) ### Changed * Allow `string` such as `wait_for` to be passed to `AbstractUpdateAction::setRefresh` [#1791](https://github.com/ruflin/Elastica/pull/1791) diff --git a/src/Transport/AwsAuthV4.php b/src/Transport/AwsAuthV4.php index b070a361c6..da25ed112a 100755 --- a/src/Transport/AwsAuthV4.php +++ b/src/Transport/AwsAuthV4.php @@ -43,7 +43,7 @@ private function getSigningMiddleware(): callable $signer = new SignatureV4('es', $region); $credProvider = $this->getCredentialProvider(); - return Middleware::mapRequest(function (RequestInterface $req) use ( + return Middleware::mapRequest(static function (RequestInterface $req) use ( $signer, $credProvider ) { diff --git a/tests/BulkTest.php b/tests/BulkTest.php index 565bfebd92..825a8dbee2 100644 --- a/tests/BulkTest.php +++ b/tests/BulkTest.php @@ -550,7 +550,7 @@ public function testUpsert(): void $doc2 = new Document(2, ['name' => 'Beckenbauer'], $index); $doc3 = new Document(3, ['name' => 'Baggio'], $index); $doc4 = new Document(4, ['name' => 'Cruyff'], $index); - $documents = \array_map(function ($d) { + $documents = \array_map(static function ($d) { $d->setDocAsUpsert(true); return $d; diff --git a/tests/Connection/Strategy/CallbackStrategyTest.php b/tests/Connection/Strategy/CallbackStrategyTest.php index ccac761777..43c77bbf05 100644 --- a/tests/Connection/Strategy/CallbackStrategyTest.php +++ b/tests/Connection/Strategy/CallbackStrategyTest.php @@ -22,7 +22,7 @@ public function testInvoke(): void { $count = 0; - $callback = function ($connections) use (&$count): Connection { + $callback = static function ($connections) use (&$count): Connection { ++$count; return \current($connections); @@ -42,7 +42,7 @@ public function testConnection(): void { $count = 0; - $config = ['connectionStrategy' => function ($connections) use (&$count): Connection { + $config = ['connectionStrategy' => static function ($connections) use (&$count): Connection { ++$count; return \current($connections); diff --git a/tests/Connection/Strategy/RoundRobinTest.php b/tests/Connection/Strategy/RoundRobinTest.php index d24ba82c2d..e044f2348c 100644 --- a/tests/Connection/Strategy/RoundRobinTest.php +++ b/tests/Connection/Strategy/RoundRobinTest.php @@ -74,7 +74,7 @@ public function testWithOneFailConnection(): void ]; $count = 0; - $callback = function ($connection, $exception, $client) use (&$count): void { + $callback = static function ($connection, $exception, $client) use (&$count): void { ++$count; }; @@ -102,7 +102,7 @@ public function testWithNoValidConnection(): void ]; $count = 0; - $client = $this->_getClient(['roundRobin' => true], function () use (&$count): void { + $client = $this->_getClient(['roundRobin' => true], static function () use (&$count): void { ++$count; }); diff --git a/tests/Connection/Strategy/SimpleTest.php b/tests/Connection/Strategy/SimpleTest.php index b457bf581a..2e9376c839 100644 --- a/tests/Connection/Strategy/SimpleTest.php +++ b/tests/Connection/Strategy/SimpleTest.php @@ -62,7 +62,7 @@ public function testWithOneFailConnection(): void ]; $count = 0; - $callback = function ($connection, $exception, $client) use (&$count): void { + $callback = static function ($connection, $exception, $client) use (&$count): void { ++$count; }; @@ -90,7 +90,7 @@ public function testWithNoValidConnection(): void ]; $count = 0; - $client = $this->_getClient([], function () use (&$count): void { + $client = $this->_getClient([], static function () use (&$count): void { ++$count; }); diff --git a/tests/Connection/Strategy/StrategyFactoryTest.php b/tests/Connection/Strategy/StrategyFactoryTest.php index 3deccb99a0..7067f0d658 100644 --- a/tests/Connection/Strategy/StrategyFactoryTest.php +++ b/tests/Connection/Strategy/StrategyFactoryTest.php @@ -21,7 +21,7 @@ class StrategyFactoryTest extends Base */ public function testCreateCallbackStrategy(): void { - $callback = function ($connections): void { + $callback = static function ($connections): void { }; $strategy = StrategyFactory::create($callback); diff --git a/tests/StatusTest.php b/tests/StatusTest.php index 117f521ebc..1945608a75 100644 --- a/tests/StatusTest.php +++ b/tests/StatusTest.php @@ -96,7 +96,7 @@ public function testAliasExists(): void $indicesWithAlias = $status->getIndicesWithAlias($aliasName); $this->assertEquals([$indexName], \array_map( - function ($index) { + static function ($index) { return $index->getName(); }, $indicesWithAlias