I created a class with the construction:

public function __construct(
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        array $data = []
    ) {

        $this->storeManager       = $storeManager;

But it get the warning:

Only dependency assignment operations are allowed in constructor. (using PHPCS)

Is there anyway I can rewrite construct function, still call the parent construct and do not get that warning. (It happen with ALL construct rewriting functions, and only happened lately, the warning is kinda new).

1 Answer 1


2.3. Class constructor can have only dependency assignment operations and/or argument validation operations. No other operations are allowed.


You should not assign empty array as predefined value

UPD: Magento core uses @SuppressWarnings(PHPMD.ExcessiveParameterList) flag to bypass such warning

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.