magento / magento/magento2-functional-testing-framework
PHP Fatal Error: Method Signature Mismatch in FinalImplementation::apply() on PHP 8.4+
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 154
- Forks
- 134
- PR merge metrics
- No merged PRs in 30d
Description
We use the following mess detector ruleset:
magento/magento2-functional-testing-framework/dev/tests/static/Magento/CodeMessDetector/ruleset.xml
When running mess detector with this ruleset, we encounter the following fatal error on PHP 8.4.8:
```text
Fatal error: Declaration of Magento\CodeMessDetector\Rule\Design\FinalImplementation::apply(PHPMD\AbstractNode $node) must be compatible with PHPMD\Rule::apply(PHPMD\AbstractNode $node): void in ./vendor/magento/magento2-functional-testing-framework/dev/tests/static/Magento/CodeMessDetector/Rule/Design/FinalImplementation.php on line 23
```
Environment:
- Magento: 2.4.8-p1
- magento/magento2-functional-testing-framework: 5.0.5
- phpmd/phpmd: 3.x-dev
- PHP: 8.4.8
A vanilla Magento install has a dev dependency for phpmd/phpmd 3.x-dev and this introduces the fatal error: https://github.com/magento/magento2/blob/2.4.8-p1/composer.json
Cause:
The method signature for `apply()` in `FinalImplementation` does not include the required `: void` return type, which is now enforced.
Patch:
```text
diff --git a/dev/tests/static/Magento/CodeMessDetector/Rule/Design/FinalImplementation.php b/dev/tests/static/Magento/CodeMessDetector/Rule/Design/FinalImplementation.php
index 4b9c99e..c1db5e3 100644
--- a/dev/tests/static/Magento/CodeMessDetector/Rule/Design/FinalImplementation.php
+++ b/dev/tests/static/Magento/CodeMessDetector/Rule/Design/FinalImplementation.php
@@ -16,11 +16,13 @@
*/
class FinalImplementation extends AbstractRule implements ClassAware, MethodAware
{
/**
* @inheritdoc
*/
- public function apply(AbstractNode $node)
+ public function apply(AbstractNode $node): void
{
if ($node->isFinal()) {
$this->addViolation($node, [$node->getType(), $node->getFullQualifiedName()]);
}
}
}
```
Please update the method signature to ensure compatibility with PHP 8.4 and newer PHPMD versions.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with dev/tests/static/Magento/CodeMessDetector/Rule/Design/FinalImplementation.php and inspect the apply() method against the reported PHPMD signature. Run the mess detector with dev/tests/static/Magento/CodeMessDetector/ruleset.xml on PHP 8.4. Done means the fatal method-signature error no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100