-
-
Notifications
You must be signed in to change notification settings - Fork 450
rector: ChangeIfElseValueAssignToEarlyReturnRector
#5210
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
base: main
Are you sure you want to change the base?
rector: ChangeIfElseValueAssignToEarlyReturnRector
#5210
Conversation
sreichel
commented
Jan 2, 2026
- see https://getrector.com/rule-detail/change-if-else-value-assign-to-early-return-rector
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 applies the Rector rule ChangeIfElseValueAssignToEarlyReturnRector to refactor if-else value assignment patterns into early return patterns, improving code readability and reducing cognitive complexity.
Key changes:
- Eliminates intermediate variable assignments by returning values directly
- Converts if-else blocks to early return patterns throughout the codebase
- Enables the
ChangeIfElseValueAssignToEarlyReturnRectorrule in.rector.php
Reviewed changes
Copilot reviewed 56 out of 56 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
.rector.php |
Removes the rule from the skip list to enable ChangeIfElseValueAssignToEarlyReturnRector |
lib/Varien/Simplexml/Element.php |
Refactors getParent() to use early return for _parent check |
lib/Varien/Object.php |
Refactors toString() to use early return for empty format check |
lib/Varien/Filter/Template.php |
Refactors includeDirective() and templateDirective() to use early returns for error cases |
lib/Varien/Data/Form/Element/Abstract.php |
Refactors getLabelHtml() and getHtml() to use early returns |
lib/Varien/Data/Collection/Db.php |
Simplifies _getMappedField() using null coalescing operator |
lib/Magento/Profiler/OutputAbstract.php |
Refactors _renderColumnValue() to use early return for time formatting |
app/code/core/Mage/Tax/Helper/Data.php |
Refactors getIncExcText() to use early return |
app/code/core/Mage/Sales/Model/Resource/Order/Status.php |
Refactors _getLoadSelect() to use early return for default_state condition |
app/code/core/Mage/Sales/Model/Order.php |
Refactors getCustomerName() to use early return |
app/code/core/Mage/Page/Block/Html/Pager.php |
Refactors getPages() to use early return for simple page range case |
app/code/core/Mage/Page/Block/Html/Head.php |
Refactors _getFaviconFile() to use early return |
app/code/core/Mage/Page/Block/Html.php |
Refactors getPrintLogoUrl() to use early return |
app/code/core/Mage/Newsletter/Model/Template.php |
Refactors getProcessedTemplate() to use early return for preprocess check |
app/code/core/Mage/ImportExport/Model/Resource/Import/Data.php |
Refactors getIterator() to use early return and updates docblock return type |
app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php |
Refactors _getAttributeConditionSql() to use early return for static attributes |
app/code/core/Mage/Eav/Model/Entity/Attribute/Set.php |
Refactors getDefaultGroupId() to use early return |
app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Abstract.php |
Refactors getClass() to use early return |
app/code/core/Mage/Eav/Model/Attribute/Data/Multiline.php |
Refactors extractValue() to use early return |
app/code/core/Mage/Eav/Model/Attribute/Data/Datetime.php |
Refactors _getFormFilter() to use early return for datetime filter |
app/code/core/Mage/Eav/Model/Attribute/Data/Abstract.php |
Refactors _getFormFilter() to use early return for date filter |
app/code/core/Mage/Directory/Model/Country.php |
Refactors formatAddress() to use early return |
app/code/core/Mage/Customer/Block/Address/Renderer/Default.php |
Refactors getFormat() to use early return for country format |
app/code/core/Mage/Customer/Block/Address/Edit.php |
Refactors getTitle() to use early return |
app/code/core/Mage/Core/Model/Cache.php |
Refactors getTagsByType() and _getInvalidatedTypes() to use early returns, updates docblock |
app/code/core/Mage/Core/Controller/Request/Http.php |
Refactors getBasePath() to use early return |
app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php |
Refactors getProductImgByLabel() to use early return |
app/code/core/Mage/Cms/Block/Block.php |
Refactors getCacheKeyInfo() to use early return |
app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php |
Refactors _unifyField() to use early return for datetime backend type |
app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php |
Refactors getCacheData() to use early return |
app/code/core/Mage/CatalogIndex/Model/Data/Abstract.php |
Refactors getTaxClassId() to use early return |
app/code/core/Mage/Catalog/Model/Resource/Collection/Abstract.php |
Refactors _getLoadAttributesSelect() to use early return for store-specific selection |
app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php |
Refactors getMainStoreTable() to use early return |
app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Price.php |
Refactors _calcSelectionPrice() to use early return |
app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php |
Refactors getSku() to use early return |
app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php |
Refactors _getUniqueFileName() to use early return for database storage check |
app/code/core/Mage/Catalog/Model/Category.php |
Refactors _getAttribute() to use early return |
app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Pager.php |
Refactors getPages() to use early return |
app/code/core/Mage/Catalog/Block/Product/Widget/Html/Pager.php |
Refactors getPages() to use early return |
app/code/core/Mage/Catalog/Block/Product/View/Options/Abstract.php |
Refactors getPrice() to use early return |
app/code/core/Mage/Catalog/Block/Navigation.php |
Refactors getCategoryUrl() to use early return |
app/code/core/Mage/Captcha/Model/Zend.php |
Refactors _getFontPath() to use early return |
app/code/core/Mage/Bundle/Model/Product/Price.php |
Refactors _getMaximalCustomOptionPrice() to use early return |
app/code/core/Mage/Api2/Block/Adminhtml/Roles/Tab/Users.php |
Refactors getUsers() to use early return for JSON encoding |
app/code/core/Mage/Adminhtml/controllers/Sales/Order/StatusController.php |
Refactors _initStatus() to use early return |
app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Abstract.php |
Refactors renderHeader() to use early return for sortable columns |
app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php |
Refactors _getDeleteUrl() to use early return |
app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Grid.php |
Refactors decorateState() to use early return |
app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Packaging/Grid.php |
Refactors getCollection() to use early return |
app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Packaging.php |
Refactors getPackages() to use early return |
app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create.php |
Refactors getHeaderText() to use early return |
app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Address.php |
Refactors getAddress() to use early return |
app/code/core/Mage/Adminhtml/Block/Sales/Order/Create.php |
Refactors getCancelUrl() to use early return |
app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Renderer/Searchquery.php |
Refactors render() to use early return for long query strings |
app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php |
Refactors getBillingAddressHtml() to use early return |
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
|
Converts nested if statements to early returns for better code readability. Thanks to @sreichel for finding this rector rule. See: OpenMage/magento-lts#5210

