magento/magento-coding-standard

Constructor property promotion and EmptyBlock rule

mfickers opened this issue · 2 comments

Description

Using the new PHP 8.0 feature of constructor property promotion, the constructor function will have an empty block:

public function __construct(
    private RequestInterface $request
) {}

This is not allowed with the current ruleset, as it violates the Magento2.CodeAnalysis.EmptyBlock rule:

WARNING | [ ] Empty FUNCTION statement detected

Expected behavior

Empty function block should be allowed in case of empty constructor using property promotion

Benefits

PHP 8.0 feature of constructor property promotion will be usable with the Magento Coding Standard

Additional information

Hi @mfickers. Thank you for your report.
To speed up processing of this issue, make sure that you provided sufficient information.

Add a comment to assign the issue: @magento I am working on this


nuzil commented

As temp workaround, use
--exclude=Magento2.CodeAnalysis.EmptyBlock

but yes, this issue is valid and have to be fixed