-
-
Notifications
You must be signed in to change notification settings - Fork 452
Phpstan: fix falsy empty #5078
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
Phpstan: fix falsy empty #5078
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves type safety and code quality by converting empty() checks to is_null() checks where properties are explicitly nullable, updating docblock types to include null, adding missing @throws annotations, and simplifying various code patterns. These changes resolve numerous PHPStan errors as evidenced by the removed entries in the baseline file.
Key changes:
- Replaced
empty()withis_null()for property initialization checks across 20+ files - Updated docblock type hints to include
nullfor properties that can be null - Added missing
@throwsannotations to methods that can throw exceptions - Simplified logic by removing redundant conditions and unused variables
Reviewed Changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/Varien/Io/Sftp.php | Added use statement, improved docblocks, removed return value from disconnect() call |
| lib/Varien/Data/Form/Abstract.php | Changed empty() to is_null() for $_elements check |
| app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract.php | Updated return type to include null, removed unused $info variable |
| app/code/core/Mage/Shipping/Model/Shipping.php | Changed empty() to is_null() for $_result check |
| app/code/core/Mage/Shipping/Model/Carrier/Abstract.php | Updated docblock type to include null |
| app/code/core/Mage/Sales/Model/Quote/Address/Total/Shipping.php | Removed unused variables and isset() check |
| app/code/core/Mage/Sales/Model/Quote.php | Added type hint comment for $message variable |
| app/code/core/Mage/Sales/Model/Order/Shipment.php | Changed empty() to is_null() for collection checks |
| app/code/core/Mage/Sales/Model/Order/Creditmemo.php | Changed empty() to is_null() for $_items check |
| app/code/core/Mage/Rule/Model/Condition/Abstract.php | Updated docblock types to include null |
| app/code/core/Mage/Rule/Model/Abstract.php | Changed empty() to is_null() for $_conditions check |
| app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php | Changed empty() to is_null() for $_entityCollection check |
| app/code/core/Mage/Install/Model/Installer/Db/Abstract.php | Changed isset() to is_null() for $_connection check |
| app/code/core/Mage/Eav/Model/Entity/Type.php | Changed empty() to is_null() for $_sets check |
| app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php | Changed empty() to is_null() for $_entity check, added @throws |
| app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php | Changed empty() to is_null() for backend/frontend/source checks, added @throws |
| app/code/core/Mage/Eav/Model/Entity/Abstract.php | Changed empty() to is_null() for $_type check, added @throws |
| app/code/core/Mage/Customer/Helper/Data.php | Updated docblock class names, changed empty() to is_null() |
| app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php | Initialized $_resource to null, simplified field selection logic, updated getResource() check |
| app/code/core/Mage/Core/Model/Mysql4/Design/Theme/Collection.php | Added unused parameters to load() method signature |
| app/code/core/Mage/Core/Model/Design/Package.php | Updated docblock type to include null |
| app/code/core/Mage/Core/Model/Design/Fallback.php | Updated docblock types, added @throws annotations |
| app/code/core/Mage/Core/Model/App.php | Changed empty() to is_null() for request/response checks |
| app/code/core/Mage/Core/Model/Abstract.php | Updated docblock type, added multiple @throws annotations |
| app/code/core/Mage/Checkout/Model/Type/Onepage.php | Updated docblock type to include null |
| app/code/core/Mage/CatalogSearch/Helper/Data.php | Changed isset() to is_null() for $_queryText check |
| app/code/core/Mage/Catalog/Model/Url.php | Updated docblock type, added @throws annotations |
| app/code/core/Mage/Catalog/Model/Resource/Config.php | Updated docblock type, removed extra spaces, added @throws |
| app/code/core/Mage/Catalog/Model/Resource/Category.php | Updated docblock types to include null |
| app/code/core/Mage/Captcha/Model/Zend.php | Changed empty() to is_null() for $_helper check |
| app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php | Added @throws, renamed $e to $exception, removed isset checks, moved comment |
| app/code/core/Mage/Adminhtml/controllers/Permissions/VariableController.php | Added @throws, renamed $e to $exception, changed isset() to simple condition |
| app/code/core/Mage/Adminhtml/controllers/Permissions/BlockController.php | Added @throws, renamed $e to $exception, changed isset() to simple condition |
| app/code/core/Mage/Adminhtml/Block/Report/Grid/Abstract.php | Changed isset() to !is_null() |
| app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php | Added string casts for integer constant values |
| app/code/core/Mage/Admin/Model/Resource/Roles.php | Renamed $role to $object parameter, added proper type hints and @throws |
| .phpstan.dist.baseline.neon | Removed 132 resolved PHPStan errors |
|
Merged. Looks safe. Tested. Tests pass. |
|


empty/issetchecks withis_null