Skip to content

Fixed undefined variable error in AutogeneratedClassNotInConstructorSniff #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

sivaschenko
Copy link
Member

@sivaschenko sivaschenko commented Oct 28, 2021

Fixes: #314

Refactored the sniff for better readability, simplified and fixed the implementation.
Added additional filtering by autogenerated class suffixes (Proxy and Interceptors are not covered as they are handled by DiscouragedDependenciesSniff)

Test results on magento2 codebase:


$ vendor/bin/phpcs --standard=Magento2 --sniffs=Magento2.PHP.AutogeneratedClassNotInConstructor magento2/app/code

FILE: magento2/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php
------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------------------------------
67 | ERROR | Class \Magento\Framework\Controller\Result\JsonFactory needs to be requested in constructor, otherwise compiler will not be able to
|       | find and generate this classes
------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: magento2/app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced/Collection.php
------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------------------------------
194 | ERROR | Class \Magento\Framework\Api\Search\SearchResultFactory needs to be requested in constructor, otherwise compiler will not be able to
|       | find and generate this classes
------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: magento2/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php
------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------------------------------
181 | ERROR | Class \Magento\Framework\Api\Search\SearchResultFactory needs to be requested in constructor, otherwise compiler will not be able to
|       | find and generate this classes
------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: magento2/app/code/Magento/Catalog/Controller/Adminhtml/Product/Builder.php
------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------------------------------
81 | ERROR | Class \Magento\Store\Model\StoreFactory needs to be requested in constructor, otherwise compiler will not be able to find and generate
|       | this classes
------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: magento2/app/code/Magento/Rule/Model/AbstractModel.php
------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------
495 | ERROR | Class \Magento\Framework\Api\ExtensionAttributesFactory needs to be requested in constructor, otherwise compiler will not be able to
|       | find and generate this classes
507 | ERROR | Class \Magento\Framework\Api\AttributeValueFactory needs to be requested in constructor, otherwise compiler will not be able to find
|       | and generate this classes
------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: magento2/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php
------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------------------------------
208 | ERROR | Class \Magento\ConfigurableProduct\Helper\Product\Options\Factory needs to be requested in constructor, otherwise compiler will not be
|       | able to find and generate this classes
------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: magento2/app/code/Magento/Customer/Controller/Account/Logout.php
------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------------------------------
75 | ERROR | Class CookieMetadataFactory needs to be requested in constructor, otherwise compiler will not be able to find and generate this classes
------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 1 mins, 59.01 secs; Memory: 64MB

@sivaschenko
Copy link
Member Author

@magento import pr to magento-commerce/magento-coding-standard

@m2-github-services
Copy link
Contributor

@sivaschenko an error occurred during the Pull Request import.

@sivaschenko
Copy link
Member Author

@magento import pr to magento-commerce/magento-coding-standard

@m2-github-services
Copy link
Contributor

@sivaschenko an error occurred during the Pull Request import.

@sivaschenko
Copy link
Member Author

@magento import pr to magento-commerce/magento-coding-standard

@m2-github-services
Copy link
Contributor

@sivaschenko an error occurred during the Pull Request import.

@sidolov
Copy link
Collaborator

sidolov commented Nov 2, 2021

@magento import pr to magento-commerce/magento-coding-standard

@m2-github-services
Copy link
Contributor

@sidolov an error occurred during the Pull Request import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AutogeneratedClassNotInConstructorSniff fails with specific code
7 participants