diff --git a/.rector.php b/.rector.php index b013daa88b..f03642946f 100644 --- a/.rector.php +++ b/.rector.php @@ -35,6 +35,7 @@ DeadCode\ClassMethod\RemoveUselessReturnTagRector::class, DeadCode\MethodCall\RemoveNullArgOnNullDefaultParamRector::class, DeadCode\Property\RemoveUselessVarTagRector::class, + EarlyReturn\If_\ChangeNestedIfsToEarlyReturnRector::class, EarlyReturn\If_\RemoveAlwaysElseRector::class, Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector::class, Rector\Php71\Rector\List_\ListToArrayDestructRector::class, diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php index 1800a3bb08..9997ead5e6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php @@ -58,15 +58,18 @@ public function getAttributeCode() */ public function canDisplayUseDefault() { - if ($attribute = $this->getAttribute()) { - if (!$attribute->isScopeGlobal() - && $this->getDataObject() - && $this->getDataObject()->getId() - && $this->getDataObject()->getStoreId() - ) { - return true; - } + if (!$attribute = $this->getAttribute()) { + return false; + } + + if (!$attribute->isScopeGlobal() + && $this->getDataObject() + && $this->getDataObject()->getId() + && $this->getDataObject()->getStoreId() + ) { + return true; } + return false; } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php index 6b9ceadfbd..bde3f5af37 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php @@ -81,10 +81,12 @@ public function getFieldValueAsFloat(string $field): float public function getConfigFieldValue($field) { - if ($this->getStockItem()) { - if ($this->getStockItem()->getData('use_config_' . $field) == 0) { - return $this->getStockItem()->getData($field); - } + if (!$this->getStockItem()) { + return Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_ITEM . $field); + } + + if ($this->getStockItem()->getData('use_config_' . $field) == 0) { + return $this->getStockItem()->getData($field); } return Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_ITEM . $field); diff --git a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php index 66ab8b1766..fbb525cb25 100644 --- a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php +++ b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php @@ -147,12 +147,11 @@ public function isChildCalculated($item = null): bool public function getBundleOptions($item = null): array { $options = $this->getOrderItem()->getProductOptions(); - if ($options) { - if (isset($options['bundle_options'])) { - return $options['bundle_options']; - } + if (!$options) { + return $options['bundle_options'] ?? []; } - return []; + + return $options['bundle_options'] ?? []; } /** diff --git a/app/code/core/Mage/Catalog/Block/Product/Abstract.php b/app/code/core/Mage/Catalog/Block/Product/Abstract.php index 6e470662f2..ff55b09b9d 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Abstract.php +++ b/app/code/core/Mage/Catalog/Block/Product/Abstract.php @@ -193,11 +193,14 @@ protected function _getPriceBlock($productTypeId) */ protected function _getPriceBlockTemplate($productTypeId) { - if (isset($this->_priceBlockTypes[$productTypeId])) { - if ($this->_priceBlockTypes[$productTypeId]['template'] != '') { - return $this->_priceBlockTypes[$productTypeId]['template']; - } + if (!isset($this->_priceBlockTypes[$productTypeId])) { + return $this->_priceBlockDefaultTemplate; + } + + if ($this->_priceBlockTypes[$productTypeId]['template'] != '') { + return $this->_priceBlockTypes[$productTypeId]['template']; } + return $this->_priceBlockDefaultTemplate; } diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php index 2b930e350e..92ce71ef00 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php @@ -727,11 +727,14 @@ public function getOrderOptions($product = null) #[\Override] public function isVirtual($product = null) { - if ($productOption = $this->getProduct($product)->getCustomOption('simple_product')) { - if ($optionProduct = $productOption->getProduct()) { - return $optionProduct->isVirtual(); - } + if (!$productOption = $this->getProduct($product)->getCustomOption('simple_product')) { + return parent::isVirtual($product); + } + + if ($optionProduct = $productOption->getProduct()) { + return $optionProduct->isVirtual(); } + return parent::isVirtual($product); } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php index ac37867922..912b19b6c2 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php @@ -243,11 +243,14 @@ public function getApplyTo() public function getSourceModel() { $model = $this->getData('source_model'); - if (empty($model)) { - if ($this->getBackendType() == 'int' && $this->getFrontendInput() == 'select') { - return $this->getDefaultSourceModel(); - } + if (!empty($model)) { + return $model; + } + + if ($this->getBackendType() == 'int' && $this->getFrontendInput() == 'select') { + return $this->getDefaultSourceModel(); } + return $model; } diff --git a/app/code/core/Mage/Core/Controller/Varien/Action.php b/app/code/core/Mage/Core/Controller/Varien/Action.php index f0966de593..4ee3131053 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Action.php +++ b/app/code/core/Mage/Core/Controller/Varien/Action.php @@ -797,16 +797,17 @@ protected function _getRefererUrl() */ protected function _isUrlInternal($url) { - if (str_contains($url, 'http')) { - /** - * Url must start from base secure or base unsecure url - */ - if (str_starts_with($url, Mage::app()->getStore()->getBaseUrl()) - || str_starts_with($url, Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true)) - ) { - return true; - } + if (!str_contains($url, 'http')) { + return false; + } + + // Url must start from base secure or base unsecure url + if (str_starts_with($url, Mage::app()->getStore()->getBaseUrl()) + || str_starts_with($url, Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true)) + ) { + return true; } + return false; } diff --git a/app/code/core/Mage/Core/Helper/String.php b/app/code/core/Mage/Core/Helper/String.php index 6f2d903b4a..0eec0c5b39 100644 --- a/app/code/core/Mage/Core/Helper/String.php +++ b/app/code/core/Mage/Core/Helper/String.php @@ -563,10 +563,12 @@ public function isSerializedArrayOrObject($data) */ public function validateSerializedObject($str) { - if ($this->isSerializedArrayOrObject($str)) { - if (!unserialize($str)) { - return false; - } + if (!$this->isSerializedArrayOrObject($str)) { + return true; + } + + if (!unserialize($str)) { + return false; } return true; diff --git a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Password.php b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Password.php index 643cb5a998..bb0aa91b81 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Password.php +++ b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Password.php @@ -49,10 +49,12 @@ public function beforeSave($object) #[\Override] public function validate($object) { - if ($password = $object->getPassword()) { - if ($password == $object->getPasswordConfirm()) { - return true; - } + if (!$password = $object->getPassword()) { + return parent::validate($object); + } + + if ($password == $object->getPasswordConfirm()) { + return true; } return parent::validate($object); diff --git a/app/code/core/Mage/Index/Model/Indexer/Abstract.php b/app/code/core/Mage/Index/Model/Indexer/Abstract.php index 53c7f6a87c..c9eceec4cf 100644 --- a/app/code/core/Mage/Index/Model/Indexer/Abstract.php +++ b/app/code/core/Mage/Index/Model/Indexer/Abstract.php @@ -104,11 +104,14 @@ public function matchEvent(Mage_Index_Model_Event $event) */ public function matchEntityAndType($entity, $type) { - if (isset($this->_matchedEntities[$entity])) { - if (in_array($type, $this->_matchedEntities[$entity])) { - return true; - } + if (!isset($this->_matchedEntities[$entity])) { + return false; + } + + if (in_array($type, $this->_matchedEntities[$entity])) { + return true; } + return false; } diff --git a/app/code/core/Mage/Rss/Block/Catalog/Abstract.php b/app/code/core/Mage/Rss/Block/Catalog/Abstract.php index 01d88cb6eb..01dc677252 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/Abstract.php +++ b/app/code/core/Mage/Rss/Block/Catalog/Abstract.php @@ -71,11 +71,14 @@ protected function _getPriceBlock($productTypeId) */ protected function _getPriceBlockTemplate($productTypeId) { - if (isset($this->_priceBlockTypes[$productTypeId])) { - if ($this->_priceBlockTypes[$productTypeId]['template'] != '') { - return $this->_priceBlockTypes[$productTypeId]['template']; - } + if (!isset($this->_priceBlockTypes[$productTypeId])) { + return $this->_priceBlockDefaultTemplate; + } + + if ($this->_priceBlockTypes[$productTypeId]['template'] != '') { + return $this->_priceBlockTypes[$productTypeId]['template']; } + return $this->_priceBlockDefaultTemplate; }