magento-coding-standard
magento-coding-standard copied to clipboard
Fatal error when use ObjectManager static methods
Preconditions
- php 7.4.22
- Use v14
Steps to reproduce
- create some class with function that call
ObjectManager::setInstance($defaultObjectManager);
Expected result
- No errors
Actual result
- Got error:
PHP Fatal error: Uncaught TypeError: Argument 2 passed to Magento2\Sniffs\PHP\AutogeneratedClassNotInConstructorSniff::validateRequestedClass() must be of the type int, bool given, called in /home/runner/work/ecommerce-backend/ecommerce-backend/magento-coding-standard/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php on line 52 and defined in /home/runner/work/ecommerce-backend/ecommerce-backend/magento-coding-standard/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php:75 Stack trace: #0 /home/runner/work/ecommerce-backend/ecommerce-backend/magento-coding-standard/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php(52): Magento2\Sniffs\PHP\AutogeneratedClassNotInConstructorSniff->validateRequestedClass() #1 /home/runner/work/ecommerce-backend/ecommerce-backend/magento-coding-standard/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): Magento2\Sniffs\PHP\AutogeneratedClassNotInConstructorSniff->process() #2 /home/runner/work/ecommerce-backend/ecommerce-backend/magento-coding-standa in /home/runner/work/ecommerce-backend/ecommerce-backend/magento-coding-standard/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php on line 75 Error: Error: Command failed: magento-coding-standard/vendor/bin/phpcs --report=checkstyle --standard=Magento2 app/code/DBI/MessageQueue/Consumer/ConsumerFactory.php app/code/DBI/MessageQueue/Consumer/Isolator.php
Hi @OleksiiStepanov. 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
- Join Magento Community Engineering Slack and ask your questions in #github channel.
@OleksiiStepanov hi, we are getting the same error. Did you find out how to fix or work around it?
This was fixed in https://github.com/magento/magento-coding-standard/pull/336.
@itaymesh please upgrade to version 16 or better.
@fredden thanks for your quick reply.
I am already using the latest version.
As a temporary workaround, I added // phpcs:ignoreFile
@itaymesh Please can you open a new issue with a description of the problem, and ideally a sample file showing the behaviour you're seeing.