rector: ChangeIfElseValueAssignToEarlyReturnRector#5210
Closed
sreichel wants to merge 5 commits into
Closed
Conversation
Contributor
sreichel
commented
Jan 2, 2026
- see https://getrector.com/rule-detail/change-if-else-value-assign-to-early-return-rector
Contributor
There was a problem hiding this comment.
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 |
|
fballiano
added a commit
to MahoCommerce/maho
that referenced
this pull request
Jan 3, 2026
Converts nested if statements to early returns for better code readability. Thanks to @sreichel for finding this rector rule. See: OpenMage/magento-lts#5210
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

