From ec9dd537a2060785d42695a67b970fb1c7bd6649 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 28 Jan 2025 10:11:22 +0100 Subject: [PATCH 1/2] [TASK] Add native type declarations for anonymous functions Also make then static if possible. --- CHANGELOG.md | 2 +- src/CSSList/CSSList.php | 2 +- src/RuleSet/RuleSet.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ca3c21c..5577e6a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ Please also have a look at our ### Changed - Use more native type declarations and strict mode - (#641, #772, #774, #778, #804) + (#641, #772, #774, #778, #804, #841) - Add visibility to all class/interface constants (#469) ### Deprecated diff --git a/src/CSSList/CSSList.php b/src/CSSList/CSSList.php index 9ea81b4c..92aadbbc 100644 --- a/src/CSSList/CSSList.php +++ b/src/CSSList/CSSList.php @@ -413,7 +413,7 @@ protected function renderListContents(OutputFormat $oOutputFormat) $oNextLevel = $oOutputFormat->nextLevel(); } foreach ($this->aContents as $oContent) { - $sRendered = $oOutputFormat->safely(function () use ($oNextLevel, $oContent) { + $sRendered = $oOutputFormat->safely(function () use ($oNextLevel, $oContent): string { return $oContent->render($oNextLevel); }); if ($sRendered === null) { diff --git a/src/RuleSet/RuleSet.php b/src/RuleSet/RuleSet.php index 62a3d313..650e067c 100644 --- a/src/RuleSet/RuleSet.php +++ b/src/RuleSet/RuleSet.php @@ -162,7 +162,7 @@ public function getRules($mRule = null) $aResult = \array_merge($aResult, $aRules); } } - \usort($aResult, function (Rule $first, Rule $second) { + \usort($aResult, static function (Rule $first, Rule $second): int { if ($first->getLineNo() === $second->getLineNo()) { return $first->getColNo() - $second->getColNo(); } @@ -266,7 +266,7 @@ protected function renderRules(OutputFormat $oOutputFormat) $oNextLevel = $oOutputFormat->nextLevel(); foreach ($this->aRules as $aRules) { foreach ($aRules as $rule) { - $sRendered = $oNextLevel->safely(function () use ($rule, $oNextLevel) { + $sRendered = $oNextLevel->safely(function () use ($rule, $oNextLevel): string { return $rule->render($oNextLevel); }); if ($sRendered === null) { From 30a1120419608d78d5dfa69d54978efe59441344 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 28 Jan 2025 23:31:20 +0100 Subject: [PATCH 2/2] Make more anonymous functions static --- src/CSSList/CSSList.php | 2 +- src/RuleSet/RuleSet.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CSSList/CSSList.php b/src/CSSList/CSSList.php index 92aadbbc..a747e90c 100644 --- a/src/CSSList/CSSList.php +++ b/src/CSSList/CSSList.php @@ -413,7 +413,7 @@ protected function renderListContents(OutputFormat $oOutputFormat) $oNextLevel = $oOutputFormat->nextLevel(); } foreach ($this->aContents as $oContent) { - $sRendered = $oOutputFormat->safely(function () use ($oNextLevel, $oContent): string { + $sRendered = $oOutputFormat->safely(static function () use ($oNextLevel, $oContent): string { return $oContent->render($oNextLevel); }); if ($sRendered === null) { diff --git a/src/RuleSet/RuleSet.php b/src/RuleSet/RuleSet.php index 650e067c..8888e9cd 100644 --- a/src/RuleSet/RuleSet.php +++ b/src/RuleSet/RuleSet.php @@ -266,7 +266,7 @@ protected function renderRules(OutputFormat $oOutputFormat) $oNextLevel = $oOutputFormat->nextLevel(); foreach ($this->aRules as $aRules) { foreach ($aRules as $rule) { - $sRendered = $oNextLevel->safely(function () use ($rule, $oNextLevel): string { + $sRendered = $oNextLevel->safely(static function () use ($rule, $oNextLevel): string { return $rule->render($oNextLevel); }); if ($sRendered === null) {