magento / magento/magento-coding-standard
Fatal error when use ObjectManager static methods
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 375
- Forks
- 165
- PR merge metrics
- No merged PRs in 30d
Description
### Preconditions
1. php 7.4.22
2. Use v14
### Steps to reproduce
1. create some class with function that call `ObjectManager::setInstance($defaultObjectManager);`
2.
### Expected result
1. No errors
### Actual result
1. 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
`
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 Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php, especially the process call at line 52 and validateRequestedClass() at line 75. Reproduce the failure with the reported PHP 7.4.22 environment and the magento-coding-standard/vendor/bin/phpcs command shown in the issue. Done means the command no longer terminates with the reported TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100