magento / magento/magento2-functional-testing-framework

PHP Fatal Error: Method Signature Mismatch in FinalImplementation::apply() on PHP 8.4+

Open
#922 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.