diff --git a/.rector.php b/.rector.php index d22287c7c76..d49be7ad381 100644 --- a/.rector.php +++ b/.rector.php @@ -73,6 +73,7 @@ DeadCode\ClassMethod\RemoveUselessReturnTagRector::class, DeadCode\Property\RemoveUselessVarTagRector::class, DeadCode\StaticCall\RemoveParentCallWithoutParentRector::class, + Php80\Switch_\ChangeSwitchToMatchRector::class, ]) ->withPreparedSets( deadCode: false, diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Wishlist.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Wishlist.php index b82e262927f..63ec832a802 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Wishlist.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Wishlist.php @@ -177,20 +177,12 @@ protected function _addColumnFilterToCollection($column) $collection = $this->getCollection(); $value = $column->getFilter()->getValue(); if ($collection && $value) { - switch ($column->getId()) { - case 'product_name': - $collection->addProductNameFilter($value); - break; - case 'store': - $collection->addStoreFilter($value); - break; - case 'days': - $collection->addDaysFilter($value); - break; - default: - $collection->addFieldToFilter($column->getIndex(), $column->getFilter()->getCondition()); - break; - } + match ($column->getId()) { + 'product_name' => $collection->addProductNameFilter($value), + 'store' => $collection->addStoreFilter($value), + 'days' => $collection->addDaysFilter($value), + default => $collection->addFieldToFilter($column->getIndex(), $column->getFilter()->getCondition()), + }; } return $this; } @@ -205,14 +197,10 @@ protected function _setCollectionOrder($column) { $collection = $this->getCollection(); if ($collection) { - switch ($column->getId()) { - case 'product_name': - $collection->setOrderByProductName($column->getDir()); - break; - default: - parent::_setCollectionOrder($column); - break; - } + match ($column->getId()) { + 'product_name' => $collection->setOrderByProductName($column->getDir()), + default => parent::_setCollectionOrder($column), + }; } return $this; } diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php index 0cba9066e00..5bb9f29df39 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php @@ -27,21 +27,13 @@ protected function _getFormat() try { $localeCode = Mage::app()->getLocale()->getLocaleCode(); $localeData = new Zend_Locale_Data(); - switch ($this->getColumn()->getPeriodType()) { - case 'month': - self::$_format = $localeData::getContent($localeCode, 'dateitem', 'yM'); - break; - - case 'year': - self::$_format = $localeData::getContent($localeCode, 'dateitem', 'y'); - break; - - default: - self::$_format = Mage::app()->getLocale()->getDateFormat( - Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, - ); - break; - } + self::$_format = match ($this->getColumn()->getPeriodType()) { + 'month' => $localeData::getContent($localeCode, 'dateitem', 'yM'), + 'year' => $localeData::getContent($localeCode, 'dateitem', 'y'), + default => Mage::app()->getLocale()->getDateFormat( + Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, + ), + }; } catch (Exception $e) { } } @@ -58,17 +50,11 @@ protected function _getFormat() public function render(Varien_Object $row) { if ($data = $row->getData($this->getColumn()->getIndex())) { - switch ($this->getColumn()->getPeriodType()) { - case 'month': - $dateFormat = 'yyyy-MM'; - break; - case 'year': - $dateFormat = 'yyyy'; - break; - default: - $dateFormat = Varien_Date::DATE_INTERNAL_FORMAT; - break; - } + $dateFormat = match ($this->getColumn()->getPeriodType()) { + 'month' => 'yyyy-MM', + 'year' => 'yyyy', + default => Varien_Date::DATE_INTERNAL_FORMAT, + }; $format = $this->_getFormat(); try { diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php index 84bd8ee1e4f..fcff0eeb803 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php @@ -49,22 +49,18 @@ public function getSubmitUrl() public function canSendCommentEmail() { - switch ($this->getParentType()) { - case 'invoice': - return Mage::helper('sales')->canSendInvoiceCommentEmail( - $this->getEntity()->getOrder()->getStore()->getId(), - ); - case 'shipment': - return Mage::helper('sales')->canSendShipmentCommentEmail( - $this->getEntity()->getOrder()->getStore()->getId(), - ); - case 'creditmemo': - return Mage::helper('sales')->canSendCreditmemoCommentEmail( - $this->getEntity()->getOrder()->getStore()->getId(), - ); - } - - return true; + return match ($this->getParentType()) { + 'invoice' => Mage::helper('sales')->canSendInvoiceCommentEmail( + $this->getEntity()->getOrder()->getStore()->getId(), + ), + 'shipment' => Mage::helper('sales')->canSendShipmentCommentEmail( + $this->getEntity()->getOrder()->getStore()->getId(), + ), + 'creditmemo' => Mage::helper('sales')->canSendCreditmemoCommentEmail( + $this->getEntity()->getOrder()->getStore()->getId(), + ), + default => true, + }; } /** diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php index 9c1e38d14f8..ce17accac3d 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php @@ -588,16 +588,12 @@ protected function _canShowField($field) if ($ifModuleEnabled && !$this->isModuleEnabled($ifModuleEnabled)) { return false; } - - switch ($this->getScope()) { - case self::SCOPE_DEFAULT: - return (bool) (int) $field->show_in_default; - case self::SCOPE_WEBSITES: - return (bool) (int) $field->show_in_website; - case self::SCOPE_STORES: - return (bool) (int) $field->show_in_store; - } - return true; + return match ($this->getScope()) { + self::SCOPE_DEFAULT => (bool) (int) $field->show_in_default, + self::SCOPE_WEBSITES => (bool) (int) $field->show_in_website, + self::SCOPE_STORES => (bool) (int) $field->show_in_store, + default => true, + }; } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Customer.php b/app/code/core/Mage/Adminhtml/Block/Tag/Customer.php index aba8b130ab3..c00ac81c906 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Customer.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Customer.php @@ -22,18 +22,11 @@ public function __construct() { parent::__construct(); - switch ($this->getRequest()->getParam('ret')) { - case 'all': - $url = $this->getUrl('*/*/'); - break; - - case 'pending': - $url = $this->getUrl('*/*/pending'); - break; - - default: - $url = $this->getUrl('*/*/'); - } + $url = match ($this->getRequest()->getParam('ret')) { + 'all' => $this->getUrl('*/*/'), + 'pending' => $this->getUrl('*/*/pending'), + default => $this->getUrl('*/*/'), + }; $this->_block = 'tag_customer'; $this->_controller = 'tag_customer'; diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Product.php b/app/code/core/Mage/Adminhtml/Block/Tag/Product.php index c07c9c50658..6ae966e4ddc 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Product.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Product.php @@ -18,18 +18,11 @@ public function __construct() { parent::__construct(); - switch ($this->getRequest()->getParam('ret')) { - case 'all': - $url = $this->getUrl('*/*/'); - break; - - case 'pending': - $url = $this->getUrl('*/*/pending'); - break; - - default: - $url = $this->getUrl('*/*/'); - } + $url = match ($this->getRequest()->getParam('ret')) { + 'all' => $this->getUrl('*/*/'), + 'pending' => $this->getUrl('*/*/pending'), + default => $this->getUrl('*/*/'), + }; $this->_block = 'tag_product'; $this->_controller = 'tag_product'; diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php index 4009cc59a6d..cc7c2283ce9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php @@ -245,67 +245,27 @@ protected function _getRendererByType() if (is_array($renderers) && isset($renderers[$type])) { return $renderers[$type]; } - - switch ($type) { - case 'date': - $rendererClass = 'adminhtml/widget_grid_column_renderer_date'; - break; - case 'datetime': - $rendererClass = 'adminhtml/widget_grid_column_renderer_datetime'; - break; - case 'number': - $rendererClass = 'adminhtml/widget_grid_column_renderer_number'; - break; - case 'currency': - $rendererClass = 'adminhtml/widget_grid_column_renderer_currency'; - break; - case 'price': - $rendererClass = 'adminhtml/widget_grid_column_renderer_price'; - break; - case 'country': - $rendererClass = 'adminhtml/widget_grid_column_renderer_country'; - break; - case 'concat': - $rendererClass = 'adminhtml/widget_grid_column_renderer_concat'; - break; - case 'action': - $rendererClass = 'adminhtml/widget_grid_column_renderer_action'; - break; - case 'options': - $rendererClass = 'adminhtml/widget_grid_column_renderer_options'; - break; - case 'checkbox': - $rendererClass = 'adminhtml/widget_grid_column_renderer_checkbox'; - break; - case 'massaction': - $rendererClass = 'adminhtml/widget_grid_column_renderer_massaction'; - break; - case 'radio': - $rendererClass = 'adminhtml/widget_grid_column_renderer_radio'; - break; - case 'input': - $rendererClass = 'adminhtml/widget_grid_column_renderer_input'; - break; - case 'select': - $rendererClass = 'adminhtml/widget_grid_column_renderer_select'; - break; - case 'text': - $rendererClass = 'adminhtml/widget_grid_column_renderer_longtext'; - break; - case 'store': - $rendererClass = 'adminhtml/widget_grid_column_renderer_store'; - break; - case 'wrapline': - $rendererClass = 'adminhtml/widget_grid_column_renderer_wrapline'; - break; - case 'theme': - $rendererClass = 'adminhtml/widget_grid_column_renderer_theme'; - break; - default: - $rendererClass = 'adminhtml/widget_grid_column_renderer_text'; - break; - } - return $rendererClass; + return match ($type) { + 'date' => 'adminhtml/widget_grid_column_renderer_date', + 'datetime' => 'adminhtml/widget_grid_column_renderer_datetime', + 'number' => 'adminhtml/widget_grid_column_renderer_number', + 'currency' => 'adminhtml/widget_grid_column_renderer_currency', + 'price' => 'adminhtml/widget_grid_column_renderer_price', + 'country' => 'adminhtml/widget_grid_column_renderer_country', + 'concat' => 'adminhtml/widget_grid_column_renderer_concat', + 'action' => 'adminhtml/widget_grid_column_renderer_action', + 'options' => 'adminhtml/widget_grid_column_renderer_options', + 'checkbox' => 'adminhtml/widget_grid_column_renderer_checkbox', + 'massaction' => 'adminhtml/widget_grid_column_renderer_massaction', + 'radio' => 'adminhtml/widget_grid_column_renderer_radio', + 'input' => 'adminhtml/widget_grid_column_renderer_input', + 'select' => 'adminhtml/widget_grid_column_renderer_select', + 'text' => 'adminhtml/widget_grid_column_renderer_longtext', + 'store' => 'adminhtml/widget_grid_column_renderer_store', + 'wrapline' => 'adminhtml/widget_grid_column_renderer_wrapline', + 'theme' => 'adminhtml/widget_grid_column_renderer_theme', + default => 'adminhtml/widget_grid_column_renderer_text', + }; } /** @@ -346,48 +306,20 @@ protected function _getFilterByType() if (is_array($filters) && isset($filters[$type])) { return $filters[$type]; } - - switch ($type) { - case 'datetime': - $filterClass = 'adminhtml/widget_grid_column_filter_datetime'; - break; - case 'date': - $filterClass = 'adminhtml/widget_grid_column_filter_date'; - break; - case 'range': - case 'number': - case 'currency': - $filterClass = 'adminhtml/widget_grid_column_filter_range'; - break; - case 'price': - $filterClass = 'adminhtml/widget_grid_column_filter_price'; - break; - case 'country': - $filterClass = 'adminhtml/widget_grid_column_filter_country'; - break; - case 'options': - $filterClass = 'adminhtml/widget_grid_column_filter_select'; - break; - case 'massaction': - $filterClass = 'adminhtml/widget_grid_column_filter_massaction'; - break; - case 'checkbox': - $filterClass = 'adminhtml/widget_grid_column_filter_checkbox'; - break; - case 'radio': - $filterClass = 'adminhtml/widget_grid_column_filter_radio'; - break; - case 'store': - $filterClass = 'adminhtml/widget_grid_column_filter_store'; - break; - case 'theme': - $filterClass = 'adminhtml/widget_grid_column_filter_theme'; - break; - default: - $filterClass = 'adminhtml/widget_grid_column_filter_text'; - break; - } - return $filterClass; + return match ($type) { + 'datetime' => 'adminhtml/widget_grid_column_filter_datetime', + 'date' => 'adminhtml/widget_grid_column_filter_date', + 'range', 'number', 'currency' => 'adminhtml/widget_grid_column_filter_range', + 'price' => 'adminhtml/widget_grid_column_filter_price', + 'country' => 'adminhtml/widget_grid_column_filter_country', + 'options' => 'adminhtml/widget_grid_column_filter_select', + 'massaction' => 'adminhtml/widget_grid_column_filter_massaction', + 'checkbox' => 'adminhtml/widget_grid_column_filter_checkbox', + 'radio' => 'adminhtml/widget_grid_column_filter_radio', + 'store' => 'adminhtml/widget_grid_column_filter_store', + 'theme' => 'adminhtml/widget_grid_column_filter_theme', + default => 'adminhtml/widget_grid_column_filter_text', + }; } /** diff --git a/app/code/core/Mage/Adminhtml/Model/Config/Data.php b/app/code/core/Mage/Adminhtml/Model/Config/Data.php index edc85b37bda..94cc10bc6f1 100644 --- a/app/code/core/Mage/Adminhtml/Model/Config/Data.php +++ b/app/code/core/Mage/Adminhtml/Model/Config/Data.php @@ -449,17 +449,12 @@ protected function _isValidField($field) if (!$field) { return false; } - - switch ($this->getScope()) { - case self::SCOPE_DEFAULT: - return (bool) (int) $field->show_in_default; - case self::SCOPE_WEBSITES: - return (bool) (int) $field->show_in_website; - case self::SCOPE_STORES: - return (bool) (int) $field->show_in_store; - } - - return true; + return match ($this->getScope()) { + self::SCOPE_DEFAULT => (bool) (int) $field->show_in_default, + self::SCOPE_WEBSITES => (bool) (int) $field->show_in_website, + self::SCOPE_STORES => (bool) (int) $field->show_in_store, + default => true, + }; } /** diff --git a/app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php b/app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php index 95625e055ea..ceb804e1cc2 100644 --- a/app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php +++ b/app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php @@ -80,20 +80,12 @@ protected function _saveOne($entityId, $giftmessage) $giftmessageModel = Mage::getModel('giftmessage/message'); $entityType = $this->_getMappedType($giftmessage['type']); - switch ($entityType) { - case 'quote': - $entityModel = $this->_getQuote(); - break; - - case 'quote_item': - $entityModel = $this->_getQuote()->getItemById($entityId); - break; - - default: - $entityModel = $giftmessageModel->getEntityModelByType($entityType) - ->load($entityId); - break; - } + $entityModel = match ($entityType) { + 'quote' => $this->_getQuote(), + 'quote_item' => $this->_getQuote()->getItemById($entityId), + default => $giftmessageModel->getEntityModelByType($entityType) + ->load($entityId), + }; if (!$entityModel) { return $this; diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php index 4029ece16c8..a4ea9b55b9e 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php @@ -365,11 +365,9 @@ public function ratingItemsAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'pending': - return Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings/reviews/pending'); - default: - return Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings/reviews/all'); - } + return match ($action) { + 'pending' => Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings/reviews/pending'), + default => Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings/reviews/all'), + }; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php b/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php index e028ee83633..b9fa6ad3ae0 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php @@ -215,15 +215,11 @@ public function preDispatch() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'new': - case 'save': - return Mage::getSingleton('admin/session')->isAllowed('cms/page/save'); - case 'delete': - return Mage::getSingleton('admin/session')->isAllowed('cms/page/delete'); - default: - return Mage::getSingleton('admin/session')->isAllowed('cms/page'); - } + return match ($action) { + 'new', 'save' => Mage::getSingleton('admin/session')->isAllowed('cms/page/save'), + 'delete' => Mage::getSingleton('admin/session')->isAllowed('cms/page/delete'), + default => Mage::getSingleton('admin/session')->isAllowed('cms/page'), + }; } /** diff --git a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php index 634deced718..fe00eb41d6f 100644 --- a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php +++ b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php @@ -809,23 +809,13 @@ public function viewfileAction() if ($plain) { $extension = pathinfo($fileName, PATHINFO_EXTENSION); - switch (strtolower($extension)) { - case 'gif': - $contentType = 'image/gif'; - break; - case 'jpg': - $contentType = 'image/jpeg'; - break; - case 'webp': - $contentType = 'image/webp'; - break; - case 'png': - $contentType = 'image/png'; - break; - default: - $contentType = 'application/octet-stream'; - break; - } + $contentType = match (strtolower($extension)) { + 'gif' => 'image/gif', + 'jpg' => 'image/jpeg', + 'webp' => 'image/webp', + 'png' => 'image/png', + default => 'application/octet-stream', + }; $ioFile->streamOpen($fileName, 'r'); $contentLength = $ioFile->streamStat('size'); diff --git a/app/code/core/Mage/Adminhtml/controllers/NotificationController.php b/app/code/core/Mage/Adminhtml/controllers/NotificationController.php index ee9b4139c79..135b99702a0 100644 --- a/app/code/core/Mage/Adminhtml/controllers/NotificationController.php +++ b/app/code/core/Mage/Adminhtml/controllers/NotificationController.php @@ -144,20 +144,11 @@ public function massRemoveAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'massmarkasread': - case 'markasread': - $acl = 'system/adminnotification/mark_as_read'; - break; - - case 'massremove': - case 'remove': - $acl = 'system/adminnotification/remove'; - break; - - default: - $acl = 'system/adminnotification/show_list'; - } + $acl = match ($action) { + 'massmarkasread', 'markasread' => 'system/adminnotification/mark_as_read', + 'massremove', 'remove' => 'system/adminnotification/remove', + default => 'system/adminnotification/show_list', + }; return Mage::getSingleton('admin/session')->isAllowed($acl); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php index 739d9e19d1f..63239f3f534 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php @@ -151,15 +151,11 @@ public function exportTotalsExcelAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'accounts': - return Mage::getSingleton('admin/session')->isAllowed('report/customers/accounts'); - case 'orders': - return Mage::getSingleton('admin/session')->isAllowed('report/customers/orders'); - case 'totals': - return Mage::getSingleton('admin/session')->isAllowed('report/customers/totals'); - default: - return Mage::getSingleton('admin/session')->isAllowed('report/customers'); - } + return match ($action) { + 'accounts' => Mage::getSingleton('admin/session')->isAllowed('report/customers/accounts'), + 'orders' => Mage::getSingleton('admin/session')->isAllowed('report/customers/orders'), + 'totals' => Mage::getSingleton('admin/session')->isAllowed('report/customers/totals'), + default => Mage::getSingleton('admin/session')->isAllowed('report/customers'), + }; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php index 840b7a6e379..514c2f5d9a6 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php @@ -234,15 +234,11 @@ public function exportDownloadsExcelAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'viewed': - return Mage::getSingleton('admin/session')->isAllowed('report/products/viewed'); - case 'sold': - return Mage::getSingleton('admin/session')->isAllowed('report/products/sold'); - case 'lowstock': - return Mage::getSingleton('admin/session')->isAllowed('report/products/lowstock'); - default: - return Mage::getSingleton('admin/session')->isAllowed('report/products'); - } + return match ($action) { + 'viewed' => Mage::getSingleton('admin/session')->isAllowed('report/products/viewed'), + 'sold' => Mage::getSingleton('admin/session')->isAllowed('report/products/sold'), + 'lowstock' => Mage::getSingleton('admin/session')->isAllowed('report/products/lowstock'), + default => Mage::getSingleton('admin/session')->isAllowed('report/products'), + }; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php b/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php index fa46983b29a..4a0921984bc 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php @@ -146,13 +146,10 @@ public function exportProductDetailExcelAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'customer': - return Mage::getSingleton('admin/session')->isAllowed('report/review/customer'); - case 'product': - return Mage::getSingleton('admin/session')->isAllowed('report/review/product'); - default: - return Mage::getSingleton('admin/session')->isAllowed('report/review'); - } + return match ($action) { + 'customer' => Mage::getSingleton('admin/session')->isAllowed('report/review/customer'), + 'product' => Mage::getSingleton('admin/session')->isAllowed('report/review/product'), + default => Mage::getSingleton('admin/session')->isAllowed('report/review'), + }; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php b/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php index 4a23b4b9b96..5909009ff11 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php @@ -374,23 +374,15 @@ public function refreshStatisticsAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'sales': - return $this->_getSession()->isAllowed('report/salesroot/sales'); - case 'tax': - return $this->_getSession()->isAllowed('report/salesroot/tax'); - case 'shipping': - return $this->_getSession()->isAllowed('report/salesroot/shipping'); - case 'invoiced': - return $this->_getSession()->isAllowed('report/salesroot/invoiced'); - case 'refunded': - return $this->_getSession()->isAllowed('report/salesroot/refunded'); - case 'coupons': - return $this->_getSession()->isAllowed('report/salesroot/coupons'); - case 'bestsellers': - return $this->_getSession()->isAllowed('report/products/bestsellers'); - default: - return $this->_getSession()->isAllowed('report/salesroot'); - } + return match ($action) { + 'sales' => $this->_getSession()->isAllowed('report/salesroot/sales'), + 'tax' => $this->_getSession()->isAllowed('report/salesroot/tax'), + 'shipping' => $this->_getSession()->isAllowed('report/salesroot/shipping'), + 'invoiced' => $this->_getSession()->isAllowed('report/salesroot/invoiced'), + 'refunded' => $this->_getSession()->isAllowed('report/salesroot/refunded'), + 'coupons' => $this->_getSession()->isAllowed('report/salesroot/coupons'), + 'bestsellers' => $this->_getSession()->isAllowed('report/products/bestsellers'), + default => $this->_getSession()->isAllowed('report/salesroot'), + }; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php b/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php index c60c0d04eb0..d487124be58 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php @@ -140,15 +140,11 @@ public function exportAbandonedExcelAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'customer': - return Mage::getSingleton('admin/session')->isAllowed('report/shopcart/customer'); - case 'product': - return Mage::getSingleton('admin/session')->isAllowed('report/shopcart/product'); - case 'abandoned': - return Mage::getSingleton('admin/session')->isAllowed('report/shopcart/abandoned'); - default: - return Mage::getSingleton('admin/session')->isAllowed('report/shopcart'); - } + return match ($action) { + 'customer' => Mage::getSingleton('admin/session')->isAllowed('report/shopcart/customer'), + 'product' => Mage::getSingleton('admin/session')->isAllowed('report/shopcart/product'), + 'abandoned' => Mage::getSingleton('admin/session')->isAllowed('report/shopcart/abandoned'), + default => Mage::getSingleton('admin/session')->isAllowed('report/shopcart'), + }; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php b/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php index 193e9d659a2..7622187f1f9 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php @@ -267,16 +267,11 @@ public function exportTagDetailExcelAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'customer': - return Mage::getSingleton('admin/session')->isAllowed('report/tags/customer'); - case 'productall': - case 'product': - return Mage::getSingleton('admin/session')->isAllowed('report/tags/product'); - case 'popular': - return Mage::getSingleton('admin/session')->isAllowed('report/tags/popular'); - default: - return Mage::getSingleton('admin/session')->isAllowed('report/tags'); - } + return match ($action) { + 'customer' => Mage::getSingleton('admin/session')->isAllowed('report/tags/customer'), + 'productall', 'product' => Mage::getSingleton('admin/session')->isAllowed('report/tags/product'), + 'popular' => Mage::getSingleton('admin/session')->isAllowed('report/tags/popular'), + default => Mage::getSingleton('admin/session')->isAllowed('report/tags'), + }; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/ReportController.php b/app/code/core/Mage/Adminhtml/controllers/ReportController.php index 5cd3d4c7446..84fe2fb3c7f 100644 --- a/app/code/core/Mage/Adminhtml/controllers/ReportController.php +++ b/app/code/core/Mage/Adminhtml/controllers/ReportController.php @@ -64,11 +64,9 @@ public function exportSearchExcelAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'search': - return Mage::getSingleton('admin/session')->isAllowed('report/search'); - default: - return Mage::getSingleton('admin/session')->isAllowed('report'); - } + return match ($action) { + 'search' => Mage::getSingleton('admin/session')->isAllowed('report/search'), + default => Mage::getSingleton('admin/session')->isAllowed('report'), + }; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php index 9bdd07e275c..eb234d87042 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php @@ -184,16 +184,10 @@ protected function _getSession() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'index': - case 'grid': - case 'view': - return Mage::getSingleton('admin/session')->isAllowed('sales/billing_agreement/actions/view'); - case 'cancel': - case 'delete': - return Mage::getSingleton('admin/session')->isAllowed('sales/billing_agreement/actions/manage'); - default: - return Mage::getSingleton('admin/session')->isAllowed('sales/billing_agreement'); - } + return match ($action) { + 'index', 'grid', 'view' => Mage::getSingleton('admin/session')->isAllowed('sales/billing_agreement/actions/view'), + 'cancel', 'delete' => Mage::getSingleton('admin/session')->isAllowed('sales/billing_agreement/actions/manage'), + default => Mage::getSingleton('admin/session')->isAllowed('sales/billing_agreement'), + }; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php index 5878eebed5c..1d744285f69 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php @@ -540,22 +540,12 @@ protected function _getAclResourse() if (in_array($action, ['index', 'save']) && $this->_getSession()->getReordered()) { $action = 'reorder'; } - switch ($action) { - case 'index': - case 'save': - $aclResource = 'sales/order/actions/create'; - break; - case 'reorder': - $aclResource = 'sales/order/actions/reorder'; - break; - case 'cancel': - $aclResource = 'sales/order/actions/cancel'; - break; - default: - $aclResource = 'sales/order/actions'; - break; - } - return $aclResource; + return match ($action) { + 'index', 'save' => 'sales/order/actions/create', + 'reorder' => 'sales/order/actions/reorder', + 'cancel' => 'sales/order/actions/cancel', + default => 'sales/order/actions', + }; } /** diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php index d39b48f90a1..854e190a869 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php @@ -647,35 +647,17 @@ public function voidPaymentAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'hold': - $aclResource = 'sales/order/actions/hold'; - break; - case 'unhold': - $aclResource = 'sales/order/actions/unhold'; - break; - case 'email': - $aclResource = 'sales/order/actions/email'; - break; - case 'cancel': - $aclResource = 'sales/order/actions/cancel'; - break; - case 'view': - $aclResource = 'sales/order/actions/view'; - break; - case 'addcomment': - $aclResource = 'sales/order/actions/comment'; - break; - case 'creditmemos': - $aclResource = 'sales/order/actions/creditmemo'; - break; - case 'reviewpayment': - $aclResource = 'sales/order/actions/review_payment'; - break; - default: - $aclResource = 'sales/order'; - break; - } + $aclResource = match ($action) { + 'hold' => 'sales/order/actions/hold', + 'unhold' => 'sales/order/actions/unhold', + 'email' => 'sales/order/actions/email', + 'cancel' => 'sales/order/actions/cancel', + 'view' => 'sales/order/actions/view', + 'addcomment' => 'sales/order/actions/comment', + 'creditmemos' => 'sales/order/actions/creditmemo', + 'reviewpayment' => 'sales/order/actions/review_payment', + default => 'sales/order', + }; return Mage::getSingleton('admin/session')->isAllowed($aclResource); } diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php index b74e92eb2d7..4b51891c713 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php @@ -113,11 +113,9 @@ public function fetchAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'fetch': - return Mage::getSingleton('admin/session')->isAllowed('sales/transactions/fetch'); - default: - return Mage::getSingleton('admin/session')->isAllowed('sales/transactions'); - } + return match ($action) { + 'fetch' => Mage::getSingleton('admin/session')->isAllowed('sales/transactions/fetch'), + default => Mage::getSingleton('admin/session')->isAllowed('sales/transactions'), + }; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/TagController.php b/app/code/core/Mage/Adminhtml/controllers/TagController.php index 4f28cc9b4cb..fd9bcfda8ff 100644 --- a/app/code/core/Mage/Adminhtml/controllers/TagController.php +++ b/app/code/core/Mage/Adminhtml/controllers/TagController.php @@ -323,13 +323,10 @@ public function massStatusAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'pending': - return Mage::getSingleton('admin/session')->isAllowed('catalog/tag/pending'); - case 'all': - return Mage::getSingleton('admin/session')->isAllowed('catalog/tag/all'); - default: - return Mage::getSingleton('admin/session')->isAllowed('catalog/tag'); - } + return match ($action) { + 'pending' => Mage::getSingleton('admin/session')->isAllowed('catalog/tag/pending'), + 'all' => Mage::getSingleton('admin/session')->isAllowed('catalog/tag/all'), + default => Mage::getSingleton('admin/session')->isAllowed('catalog/tag'), + }; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php index 79580aadcc5..3c88f87e1db 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php @@ -454,12 +454,9 @@ public function exportPostAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'importexport': - return Mage::getSingleton('admin/session')->isAllowed('sales/tax/import_export'); - case 'index': - default: - return Mage::getSingleton('admin/session')->isAllowed('sales/tax/rates'); - } + return match ($action) { + 'importexport' => Mage::getSingleton('admin/session')->isAllowed('sales/tax/import_export'), + default => Mage::getSingleton('admin/session')->isAllowed('sales/tax/rates'), + }; } } diff --git a/app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php b/app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php index e2c457355ec..1c95f09eb7d 100644 --- a/app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php +++ b/app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php @@ -109,17 +109,10 @@ public function getRowUrl($row) */ public function decorateUserType($renderedValue, $row, $column, $isExport) { - switch ($row->getEntityId()) { - case Mage_Api2_Model_Acl_Global_Role::ROLE_GUEST_ID: - $userType = Mage::helper('api2')->__('Guest'); - break; - case Mage_Api2_Model_Acl_Global_Role::ROLE_CUSTOMER_ID: - $userType = Mage::helper('api2')->__('Customer'); - break; - default: - $userType = Mage::helper('api2')->__('Admin'); - break; - } - return $userType; + return match ($row->getEntityId()) { + Mage_Api2_Model_Acl_Global_Role::ROLE_GUEST_ID => Mage::helper('api2')->__('Guest'), + Mage_Api2_Model_Acl_Global_Role::ROLE_CUSTOMER_ID => Mage::helper('api2')->__('Customer'), + default => Mage::helper('api2')->__('Admin'), + }; } } diff --git a/app/code/core/Mage/Catalog/Block/Product/Widget/New.php b/app/code/core/Mage/Catalog/Block/Product/Widget/New.php index 037617d6c87..422efef9499 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Widget/New.php +++ b/app/code/core/Mage/Catalog/Block/Product/Widget/New.php @@ -65,15 +65,10 @@ protected function _construct() */ protected function _getProductCollection() { - switch ($this->getDisplayType()) { - case self::DISPLAY_TYPE_NEW_PRODUCTS: - $collection = parent::_getProductCollection(); - break; - default: - $collection = $this->_getRecentlyAddedProductsCollection(); - break; - } - return $collection; + return match ($this->getDisplayType()) { + self::DISPLAY_TYPE_NEW_PRODUCTS => parent::_getProductCollection(), + default => $this->_getRecentlyAddedProductsCollection(), + }; } /** diff --git a/app/code/core/Mage/Catalog/Helper/Product/Configuration.php b/app/code/core/Mage/Catalog/Helper/Product/Configuration.php index 6b66cc845b9..56bb32472e6 100644 --- a/app/code/core/Mage/Catalog/Helper/Product/Configuration.php +++ b/app/code/core/Mage/Catalog/Helper/Product/Configuration.php @@ -140,13 +140,11 @@ public function getGroupedOptions(Mage_Catalog_Model_Product_Configuration_Item_ public function getOptions(Mage_Catalog_Model_Product_Configuration_Item_Interface $item) { $typeId = $item->getProduct()->getTypeId(); - switch ($typeId) { - case Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE: - return $this->getConfigurableOptions($item); - case Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE: - return $this->getGroupedOptions($item); - } - return $this->getCustomOptions($item); + return match ($typeId) { + Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE => $this->getConfigurableOptions($item), + Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE => $this->getGroupedOptions($item), + default => $this->getCustomOptions($item), + }; } /** diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php index 0d6def5a765..e9e9c2f745f 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php @@ -281,46 +281,32 @@ public function info($attribute) } // set additional fields to different types - switch ($model->getFrontendInput()) { - case 'text': - $result['additional_fields'] = [ - 'frontend_class' => $model->getFrontendClass(), - 'is_html_allowed_on_front' => $model->getIsHtmlAllowedOnFront(), - 'used_for_sort_by' => $model->getUsedForSortBy(), - ]; - break; - case 'textarea': - $result['additional_fields'] = [ - 'is_wysiwyg_enabled' => $model->getIsWysiwygEnabled(), - 'is_html_allowed_on_front' => $model->getIsHtmlAllowedOnFront(), - ]; - break; - case 'date': - case 'boolean': - $result['additional_fields'] = [ - 'used_for_sort_by' => $model->getUsedForSortBy(), - ]; - break; - case 'multiselect': - $result['additional_fields'] = [ - 'is_filterable' => $model->getIsFilterable(), - 'is_filterable_in_search' => $model->getIsFilterableInSearch(), - 'position' => $model->getPosition(), - ]; - break; - case 'select': - case 'price': - $result['additional_fields'] = [ - 'is_filterable' => $model->getIsFilterable(), - 'is_filterable_in_search' => $model->getIsFilterableInSearch(), - 'position' => $model->getPosition(), - 'used_for_sort_by' => $model->getUsedForSortBy(), - ]; - break; - default: - $result['additional_fields'] = []; - break; - } + $result['additional_fields'] = match ($model->getFrontendInput()) { + 'text' => [ + 'frontend_class' => $model->getFrontendClass(), + 'is_html_allowed_on_front' => $model->getIsHtmlAllowedOnFront(), + 'used_for_sort_by' => $model->getUsedForSortBy(), + ], + 'textarea' => [ + 'is_wysiwyg_enabled' => $model->getIsWysiwygEnabled(), + 'is_html_allowed_on_front' => $model->getIsHtmlAllowedOnFront(), + ], + 'date', 'boolean' => [ + 'used_for_sort_by' => $model->getUsedForSortBy(), + ], + 'multiselect' => [ + 'is_filterable' => $model->getIsFilterable(), + 'is_filterable_in_search' => $model->getIsFilterableInSearch(), + 'position' => $model->getPosition(), + ], + 'select', 'price' => [ + 'is_filterable' => $model->getIsFilterable(), + 'is_filterable_in_search' => $model->getIsFilterableInSearch(), + 'position' => $model->getPosition(), + 'used_for_sort_by' => $model->getUsedForSortBy(), + ], + default => [], + }; // set options $options = $this->options($model->getId()); diff --git a/app/code/core/Mage/Catalog/Model/Product/Option.php b/app/code/core/Mage/Catalog/Model/Product/Option.php index 57701c8e806..71f1cacbcd3 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option.php @@ -564,11 +564,9 @@ protected function _clearReferences() */ public function isMultipleType() { - switch ($this->getType()) { - case self::OPTION_TYPE_MULTIPLE: - case self::OPTION_TYPE_CHECKBOX: - return true; - } - return false; + return match ($this->getType()) { + self::OPTION_TYPE_MULTIPLE, self::OPTION_TYPE_CHECKBOX => true, + default => false, + }; } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php index 30d46f5777a..f66114ab317 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php @@ -552,20 +552,12 @@ protected function _sqlIndexDefinition($indexName, $indexProp) } $indexNameQuote = $this->_getReadAdapter()->quoteIdentifier($indexName); - switch (strtolower($indexProp['type'])) { - case 'primary': - $condition = 'PRIMARY KEY'; - break; - case 'unique': - $condition = 'UNIQUE ' . $indexNameQuote; - break; - case 'fulltext': - $condition = 'FULLTEXT ' . $indexNameQuote; - break; - default: - $condition = 'INDEX ' . $indexNameQuote; - break; - } + $condition = match (strtolower($indexProp['type'])) { + 'primary' => 'PRIMARY KEY', + 'unique' => 'UNIQUE ' . $indexNameQuote, + 'fulltext' => 'FULLTEXT ' . $indexNameQuote, + default => 'INDEX ' . $indexNameQuote, + }; return sprintf('%s (%s)', $condition, $fieldSql); } diff --git a/app/code/core/Mage/CatalogRule/Helper/Data.php b/app/code/core/Mage/CatalogRule/Helper/Data.php index 43293046ebc..d6afc5a7982 100644 --- a/app/code/core/Mage/CatalogRule/Helper/Data.php +++ b/app/code/core/Mage/CatalogRule/Helper/Data.php @@ -25,20 +25,12 @@ class Mage_CatalogRule_Helper_Data extends Mage_Core_Helper_Abstract public function calcPriceRule($actionOperator, $ruleAmount, $price) { $priceRule = 0; - switch ($actionOperator) { - case 'to_fixed': - $priceRule = min($ruleAmount, $price); - break; - case 'to_percent': - $priceRule = $price * $ruleAmount / 100; - break; - case 'by_fixed': - $priceRule = max(0, $price - $ruleAmount); - break; - case 'by_percent': - $priceRule = $price * (1 - $ruleAmount / 100); - break; - } - return $priceRule; + return match ($actionOperator) { + 'to_fixed' => min($ruleAmount, $price), + 'to_percent' => $price * $ruleAmount / 100, + 'by_fixed' => max(0, $price - $ruleAmount), + 'by_percent' => $price * (1 - $ruleAmount / 100), + default => $priceRule, + }; } } diff --git a/app/code/core/Mage/Centinel/Helper/Data.php b/app/code/core/Mage/Centinel/Helper/Data.php index 0db3a4657c6..be530f4a654 100644 --- a/app/code/core/Mage/Centinel/Helper/Data.php +++ b/app/code/core/Mage/Centinel/Helper/Data.php @@ -24,19 +24,14 @@ class Mage_Centinel_Helper_Data extends Mage_Core_Helper_Abstract */ public function getCmpiLabel($fieldName) { - switch ($fieldName) { - case Mage_Centinel_Model_Service::CMPI_PARES: - return $this->__('3D Secure Verification Result'); - case Mage_Centinel_Model_Service::CMPI_ENROLLED: - return $this->__('3D Secure Cardholder Validation'); - case Mage_Centinel_Model_Service::CMPI_ECI: - return $this->__('3D Secure Electronic Commerce Indicator'); - case Mage_Centinel_Model_Service::CMPI_CAVV: - return $this->__('3D Secure CAVV'); - case Mage_Centinel_Model_Service::CMPI_XID: - return $this->__('3D Secure XID'); - } - return ''; + return match ($fieldName) { + Mage_Centinel_Model_Service::CMPI_PARES => $this->__('3D Secure Verification Result'), + Mage_Centinel_Model_Service::CMPI_ENROLLED => $this->__('3D Secure Cardholder Validation'), + Mage_Centinel_Model_Service::CMPI_ECI => $this->__('3D Secure Electronic Commerce Indicator'), + Mage_Centinel_Model_Service::CMPI_CAVV => $this->__('3D Secure CAVV'), + Mage_Centinel_Model_Service::CMPI_XID => $this->__('3D Secure XID'), + default => '', + }; } /** @@ -48,18 +43,13 @@ public function getCmpiLabel($fieldName) */ public function getCmpiValue($fieldName, $value) { - switch ($fieldName) { - case Mage_Centinel_Model_Service::CMPI_PARES: - return $this->_getCmpiParesValue($value); - case Mage_Centinel_Model_Service::CMPI_ENROLLED: - return $this->_getCmpiEnrolledValue($value); - case Mage_Centinel_Model_Service::CMPI_ECI: - return $this->_getCmpiEciValue($value); - case Mage_Centinel_Model_Service::CMPI_CAVV: // break intentionally omitted - case Mage_Centinel_Model_Service::CMPI_XID: - return $value; - } - return ''; + return match ($fieldName) { + Mage_Centinel_Model_Service::CMPI_PARES => $this->_getCmpiParesValue($value), + Mage_Centinel_Model_Service::CMPI_ENROLLED => $this->_getCmpiEnrolledValue($value), + Mage_Centinel_Model_Service::CMPI_ECI => $this->_getCmpiEciValue($value), + Mage_Centinel_Model_Service::CMPI_CAVV, Mage_Centinel_Model_Service::CMPI_XID => $value, + default => '', + }; } /** @@ -70,17 +60,11 @@ public function getCmpiValue($fieldName, $value) */ private function _getCmpiEciValue($value) { - switch ($value) { - case '01': - case '07': - return $this->__('Merchant Liability'); - case '02': - case '05': - case '06': - return $this->__('Card Issuer Liability'); - default: - return $value; - } + return match ($value) { + '01', '07' => $this->__('Merchant Liability'), + '02', '05', '06' => $this->__('Card Issuer Liability'), + default => $value, + }; } /** @@ -91,15 +75,11 @@ private function _getCmpiEciValue($value) */ private function _getCmpiEnrolledValue($value) { - switch ($value) { - case 'Y': - return $this->__('Enrolled'); - case 'U': - return $this->__('Enrolled but Authentication Unavailable'); - case 'N': // break intentionally omitted - default: - return $this->__('Not Enrolled'); - } + return match ($value) { + 'Y' => $this->__('Enrolled'), + 'U' => $this->__('Enrolled but Authentication Unavailable'), + default => $this->__('Not Enrolled'), + }; } /** @@ -110,18 +90,13 @@ private function _getCmpiEnrolledValue($value) */ private function _getCmpiParesValue($value) { - switch ($value) { - case 'Y': - return $this->__('Successful'); - case 'N': - return $this->__('Failed'); - case 'U': - return $this->__('Unable to complete'); - case 'A': - return $this->__('Successful attempt'); - default: - return $value; - } + return match ($value) { + 'Y' => $this->__('Successful'), + 'N' => $this->__('Failed'), + 'U' => $this->__('Unable to complete'), + 'A' => $this->__('Successful attempt'), + default => $value, + }; } /** diff --git a/app/code/core/Mage/Checkout/controllers/CartController.php b/app/code/core/Mage/Checkout/controllers/CartController.php index d2cc366ae21..6a3824770f9 100644 --- a/app/code/core/Mage/Checkout/controllers/CartController.php +++ b/app/code/core/Mage/Checkout/controllers/CartController.php @@ -429,16 +429,11 @@ public function updatePostAction() $updateAction = (string) $this->getRequest()->getParam('update_cart_action'); - switch ($updateAction) { - case 'empty_cart': - $this->_emptyShoppingCart(); - break; - case 'update_qty': - $this->_updateShoppingCart(); - break; - default: - $this->_updateShoppingCart(); - } + match ($updateAction) { + 'empty_cart' => $this->_emptyShoppingCart(), + 'update_qty' => $this->_updateShoppingCart(), + default => $this->_updateShoppingCart(), + }; $this->_goBack(); } diff --git a/app/code/core/Mage/Core/Model/Config.php b/app/code/core/Mage/Core/Model/Config.php index 3b157cfbdc7..b31e80790b0 100644 --- a/app/code/core/Mage/Core/Model/Config.php +++ b/app/code/core/Mage/Core/Model/Config.php @@ -1240,26 +1240,14 @@ public function getModuleDir($type, $moduleName) $codePool = (string) $this->getModuleConfig($moduleName)->codePool; $dir = $this->getOptions()->getCodeDir() . DS . $codePool . DS . uc_words($moduleName, DS); - switch ($type) { - case 'etc': - $dir .= DS . 'etc'; - break; - - case 'controllers': - $dir .= DS . 'controllers'; - break; - - case 'sql': - $dir .= DS . 'sql'; - break; - case 'data': - $dir .= DS . 'data'; - break; - - case 'locale': - $dir .= DS . 'locale'; - break; - } + match ($type) { + 'etc' => $dir .= DS . 'etc', + 'controllers' => $dir .= DS . 'controllers', + 'sql' => $dir .= DS . 'sql', + 'data' => $dir .= DS . 'data', + 'locale' => $dir .= DS . 'locale', + default => str_replace('/', DS, $dir), + }; return str_replace('/', DS, $dir); } @@ -1282,24 +1270,17 @@ public function loadEventObservers($area) $eventName = strtolower($event->getName()); $observers = $event->observers->children(); foreach ($observers as $observer) { - switch ((string) $observer->type) { - case 'singleton': - $callback = [ - Mage::getSingleton((string) $observer->class), - (string) $observer->method, - ]; - break; - case 'object': - case 'model': - $callback = [ - Mage::getModel((string) $observer->class), - (string) $observer->method, - ]; - break; - default: - $callback = [$observer->getClassName(), (string) $observer->method]; - break; - } + $callback = match ((string) $observer->type) { + 'singleton' => [ + Mage::getSingleton((string) $observer->class), + (string) $observer->method, + ], + 'object', 'model' => [ + Mage::getModel((string) $observer->class), + (string) $observer->method, + ], + default => [$observer->getClassName(), (string) $observer->method], + }; $args = (array) $observer->args; $observerClass = $observer->observer_class ? (string) $observer->observer_class : ''; diff --git a/app/code/core/Mage/Core/Model/Design/Package.php b/app/code/core/Mage/Core/Model/Design/Package.php index 7f10f38d40d..6ffe5fc95f9 100644 --- a/app/code/core/Mage/Core/Model/Design/Package.php +++ b/app/code/core/Mage/Core/Model/Design/Package.php @@ -388,19 +388,11 @@ public function validateFile($file, array $params) */ protected function _renderFilename($file, array $params) { - switch ($params['_type']) { - case 'skin': - $dir = $this->getSkinBaseDir($params); - break; - - case 'locale': - $dir = $this->getLocaleBaseDir($params); - break; - - default: - $dir = $this->getBaseDir($params); - break; - } + $dir = match ($params['_type']) { + 'skin' => $this->getSkinBaseDir($params), + 'locale' => $this->getLocaleBaseDir($params), + default => $this->getBaseDir($params), + }; return $dir . DS . $file; } diff --git a/app/code/core/Mage/Core/Model/Domainpolicy.php b/app/code/core/Mage/Core/Model/Domainpolicy.php index 09b5d3e5662..7185f8336d4 100644 --- a/app/code/core/Mage/Core/Model/Domainpolicy.php +++ b/app/code/core/Mage/Core/Model/Domainpolicy.php @@ -101,14 +101,9 @@ public function getFrontendPolicy() */ protected function _getDomainPolicyByCode($policyCode) { - switch ($policyCode) { - case self::FRAME_POLICY_ALLOW: - $policy = null; - break; - default: - $policy = 'SAMEORIGIN'; - } - - return $policy; + return match ($policyCode) { + self::FRAME_POLICY_ALLOW => null, + default => 'SAMEORIGIN', + }; } } diff --git a/app/code/core/Mage/Core/Model/Email/Queue.php b/app/code/core/Mage/Core/Model/Email/Queue.php index 6f015d56dd0..07e399c34c6 100644 --- a/app/code/core/Mage/Core/Model/Email/Queue.php +++ b/app/code/core/Mage/Core/Model/Email/Queue.php @@ -192,16 +192,10 @@ public function send() $mailer = new Zend_Mail('utf-8'); foreach ($message->getRecipients() as $recipient) { [$email, $name, $type] = $recipient; - switch ($type) { - case self::EMAIL_TYPE_BCC: - $mailer->addBcc($email, '=?utf-8?B?' . base64_encode($name) . '?='); - break; - case self::EMAIL_TYPE_TO: - case self::EMAIL_TYPE_CC: - default: - $mailer->addTo($email, '=?utf-8?B?' . base64_encode($name) . '?='); - break; - } + match ($type) { + self::EMAIL_TYPE_BCC => $mailer->addBcc($email, '=?utf-8?B?' . base64_encode($name) . '?='), + default => $mailer->addTo($email, '=?utf-8?B?' . base64_encode($name) . '?='), + }; } if ($parameters->getIsPlain()) { diff --git a/app/code/core/Mage/Core/Model/Email/Template.php b/app/code/core/Mage/Core/Model/Email/Template.php index ec09d53af93..0a95a9c80e6 100644 --- a/app/code/core/Mage/Core/Model/Email/Template.php +++ b/app/code/core/Mage/Core/Model/Email/Template.php @@ -386,17 +386,11 @@ public function send($email, $name = null, array $variables = []) $subject = $this->getProcessedTemplateSubject($variables); $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH); - switch ($setReturnPath) { - case 1: - $returnPathEmail = $this->getSenderEmail(); - break; - case 2: - $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL); - break; - default: - $returnPathEmail = null; - break; - } + $returnPathEmail = match ($setReturnPath) { + 1 => $this->getSenderEmail(), + 2 => Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL), + default => null, + }; if ($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) { $emailQueue = $this->getQueue(); diff --git a/app/code/core/Mage/Core/Model/Email/Template/Filter.php b/app/code/core/Mage/Core/Model/Email/Template/Filter.php index b3fedd4486f..763e653cb8f 100644 --- a/app/code/core/Mage/Core/Model/Email/Template/Filter.php +++ b/app/code/core/Mage/Core/Model/Email/Template/Filter.php @@ -401,17 +401,12 @@ protected function _amplifyModifiers($value, $modifiers) */ public function modifierEscape($value, $type = 'html') { - switch ($type) { - case 'html': - return htmlspecialchars($value, ENT_QUOTES); - - case 'htmlentities': - return htmlentities($value, ENT_QUOTES); - - case 'url': - return rawurlencode($value); - } - return $value; + return match ($type) { + 'html' => htmlspecialchars($value, ENT_QUOTES), + 'htmlentities' => htmlentities($value, ENT_QUOTES), + 'url' => rawurlencode($value), + default => $value, + }; } /** diff --git a/app/code/core/Mage/Core/Model/Message.php b/app/code/core/Mage/Core/Model/Message.php index cec253980a0..5f9a4c232a2 100644 --- a/app/code/core/Mage/Core/Model/Message.php +++ b/app/code/core/Mage/Core/Model/Message.php @@ -28,20 +28,12 @@ class Mage_Core_Model_Message */ protected function _factory($code, $type, $class = '', $method = '') { - switch (strtolower($type)) { - case self::ERROR: - $message = new Mage_Core_Model_Message_Error($code); - break; - case self::WARNING: - $message = new Mage_Core_Model_Message_Warning($code); - break; - case self::SUCCESS: - $message = new Mage_Core_Model_Message_Success($code); - break; - default: - $message = new Mage_Core_Model_Message_Notice($code); - break; - } + $message = match (strtolower($type)) { + self::ERROR => new Mage_Core_Model_Message_Error($code), + self::WARNING => new Mage_Core_Model_Message_Warning($code), + self::SUCCESS => new Mage_Core_Model_Message_Success($code), + default => new Mage_Core_Model_Message_Notice($code), + }; $message->setClass($class); $message->setMethod($method); diff --git a/app/code/core/Mage/Core/Model/Resource/Setup.php b/app/code/core/Mage/Core/Model/Resource/Setup.php index 11f332a5d77..55dbe6a80cd 100644 --- a/app/code/core/Mage/Core/Model/Resource/Setup.php +++ b/app/code/core/Mage/Core/Model/Resource/Setup.php @@ -546,16 +546,11 @@ protected function _getAvailableDataFiles($actionType, $fromVersion, $toVersion) */ protected function _setResourceVersion($actionType, $version) { - switch ($actionType) { - case self::TYPE_DB_INSTALL: - case self::TYPE_DB_UPGRADE: - $this->_getResource()->setDbVersion($this->_resourceName, $version); - break; - case self::TYPE_DATA_INSTALL: - case self::TYPE_DATA_UPGRADE: - $this->_getResource()->setDataVersion($this->_resourceName, $version); - break; - } + match ($actionType) { + self::TYPE_DB_INSTALL, self::TYPE_DB_UPGRADE => $this->_getResource()->setDbVersion($this->_resourceName, $version), + self::TYPE_DATA_INSTALL, self::TYPE_DATA_UPGRADE => $this->_getResource()->setDataVersion($this->_resourceName, $version), + default => $this, + }; return $this; } @@ -572,19 +567,11 @@ protected function _setResourceVersion($actionType, $version) protected function _modifyResourceDb($actionType, $fromVersion, $toVersion) { - switch ($actionType) { - case self::TYPE_DB_INSTALL: - case self::TYPE_DB_UPGRADE: - $files = $this->_getAvailableDbFiles($actionType, $fromVersion, $toVersion); - break; - case self::TYPE_DATA_INSTALL: - case self::TYPE_DATA_UPGRADE: - $files = $this->_getAvailableDataFiles($actionType, $fromVersion, $toVersion); - break; - default: - $files = []; - break; - } + $files = match ($actionType) { + self::TYPE_DB_INSTALL, self::TYPE_DB_UPGRADE => $this->_getAvailableDbFiles($actionType, $fromVersion, $toVersion), + self::TYPE_DATA_INSTALL, self::TYPE_DATA_UPGRADE => $this->_getAvailableDataFiles($actionType, $fromVersion, $toVersion), + default => [], + }; if (empty($files) || !$this->getConnection()) { return false; } diff --git a/app/code/core/Mage/Core/functions.php b/app/code/core/Mage/Core/functions.php index cdc19b80d2b..3135bbc94ae 100644 --- a/app/code/core/Mage/Core/functions.php +++ b/app/code/core/Mage/Core/functions.php @@ -126,53 +126,24 @@ function mageCoreErrorHandler($errno, $errstr, $errfile, $errline) $errorMessage = ''; - switch ($errno) { - case E_ERROR: - $errorMessage .= 'Error'; - break; - case E_WARNING: - $errorMessage .= 'Warning'; - break; - case E_PARSE: - $errorMessage .= 'Parse Error'; - break; - case E_NOTICE: - $errorMessage .= 'Notice'; - break; - case E_CORE_ERROR: - $errorMessage .= 'Core Error'; - break; - case E_CORE_WARNING: - $errorMessage .= 'Core Warning'; - break; - case E_COMPILE_ERROR: - $errorMessage .= 'Compile Error'; - break; - case E_COMPILE_WARNING: - $errorMessage .= 'Compile Warning'; - break; - case E_USER_ERROR: - $errorMessage .= 'User Error'; - break; - case E_USER_WARNING: - $errorMessage .= 'User Warning'; - break; - case E_USER_NOTICE: - $errorMessage .= 'User Notice'; - break; - case 2048: // E_STRICT prior to PHP8.4 - $errorMessage .= 'Strict Notice'; - break; - case E_RECOVERABLE_ERROR: - $errorMessage .= 'Recoverable Error'; - break; - case E_DEPRECATED: - $errorMessage .= 'Deprecated functionality'; - break; - default: - $errorMessage .= "Unknown error ($errno)"; - break; - } + match ($errno) { + E_ERROR => $errorMessage .= 'Error', + E_WARNING => $errorMessage .= 'Warning', + E_PARSE => $errorMessage .= 'Parse Error', + E_NOTICE => $errorMessage .= 'Notice', + E_CORE_ERROR => $errorMessage .= 'Core Error', + E_CORE_WARNING => $errorMessage .= 'Core Warning', + E_COMPILE_ERROR => $errorMessage .= 'Compile Error', + E_COMPILE_WARNING => $errorMessage .= 'Compile Warning', + E_USER_ERROR => $errorMessage .= 'User Error', + E_USER_WARNING => $errorMessage .= 'User Warning', + E_USER_NOTICE => $errorMessage .= 'User Notice', + // E_STRICT prior to PHP8.4 + 2048 => $errorMessage .= 'Strict Notice', + E_RECOVERABLE_ERROR => $errorMessage .= 'Recoverable Error', + E_DEPRECATED => $errorMessage .= 'Deprecated functionality', + default => $errorMessage .= "Unknown error ($errno)", + }; $errorMessage .= ": {$errstr} in {$errfile} on line {$errline}"; if (Mage::getIsDeveloperMode()) { diff --git a/app/code/core/Mage/Customer/Block/Address/Renderer/Default.php b/app/code/core/Mage/Customer/Block/Address/Renderer/Default.php index 124ec45bb7d..45997267dbb 100644 --- a/app/code/core/Mage/Customer/Block/Address/Renderer/Default.php +++ b/app/code/core/Mage/Customer/Block/Address/Renderer/Default.php @@ -69,20 +69,12 @@ public function getFormat(?Mage_Customer_Model_Address_Abstract $address = null) */ public function render(Mage_Customer_Model_Address_Abstract $address, $format = null) { - switch ($this->getType()->getCode()) { - case 'html': - $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_HTML; - break; - case 'pdf': - $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_PDF; - break; - case 'oneline': - $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ONELINE; - break; - default: - $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_TEXT; - break; - } + $dataFormat = match ($this->getType()->getCode()) { + 'html' => Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_HTML, + 'pdf' => Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_PDF, + 'oneline' => Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ONELINE, + default => Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_TEXT, + }; $formater = new Varien_Filter_Template(); $attributes = Mage::helper('customer/address')->getAttributes(); diff --git a/app/code/core/Mage/Customer/controllers/AccountController.php b/app/code/core/Mage/Customer/controllers/AccountController.php index afdf9172bdb..dc792b31e75 100644 --- a/app/code/core/Mage/Customer/controllers/AccountController.php +++ b/app/code/core/Mage/Customer/controllers/AccountController.php @@ -550,19 +550,16 @@ protected function _welcomeCustomer(Mage_Customer_Model_Customer $customer, $isJ $helper = $this->_getHelper('customer/address'); $configAddressType = $helper->getTaxCalculationAddressType(); $userPrompt = ''; - switch ($configAddressType) { - case Mage_Customer_Model_Address_Abstract::TYPE_SHIPPING: - $userPrompt = $this->__( - 'If you are a registered VAT customer, please click here to enter you shipping address for proper VAT calculation', - $this->_getUrl('customer/address/edit'), - ); - break; - default: - $userPrompt = $this->__( - 'If you are a registered VAT customer, please click here to enter you billing address for proper VAT calculation', - $this->_getUrl('customer/address/edit'), - ); - } + $userPrompt = match ($configAddressType) { + Mage_Customer_Model_Address_Abstract::TYPE_SHIPPING => $this->__( + 'If you are a registered VAT customer, please click here to enter you shipping address for proper VAT calculation', + $this->_getUrl('customer/address/edit'), + ), + default => $this->__( + 'If you are a registered VAT customer, please click here to enter you billing address for proper VAT calculation', + $this->_getUrl('customer/address/edit'), + ), + }; $this->_getSession()->addSuccess($userPrompt); } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php index 960532e7c94..6f2a7635819 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php @@ -101,17 +101,11 @@ public function getOptionValues() $defaultValues = []; } - switch ($attributeType) { - case 'select': - $inputType = 'radio'; - break; - case 'multiselect': - $inputType = 'checkbox'; - break; - default: - $inputType = ''; - break; - } + $inputType = match ($attributeType) { + 'select' => 'radio', + 'multiselect' => 'checkbox', + default => '', + }; $values = $this->getData('option_values'); if (is_null($values)) { diff --git a/app/code/core/Mage/Eav/Model/Attribute/Data/Boolean.php b/app/code/core/Mage/Eav/Model/Attribute/Data/Boolean.php index f3119297aac..6caea20f94e 100644 --- a/app/code/core/Mage/Eav/Model/Attribute/Data/Boolean.php +++ b/app/code/core/Mage/Eav/Model/Attribute/Data/Boolean.php @@ -22,17 +22,10 @@ class Mage_Eav_Model_Attribute_Data_Boolean extends Mage_Eav_Model_Attribute_Dat */ protected function _getOptionText($value) { - switch ($value) { - case '0': - $text = Mage::helper('eav')->__('No'); - break; - case '1': - $text = Mage::helper('eav')->__('Yes'); - break; - default: - $text = ''; - break; - } - return $text; + return match ($value) { + '0' => Mage::helper('eav')->__('No'), + '1' => Mage::helper('eav')->__('Yes'), + default => '', + }; } } diff --git a/app/code/core/Mage/Eav/Model/Attribute/Data/Multiline.php b/app/code/core/Mage/Eav/Model/Attribute/Data/Multiline.php index fa0078021ee..a8b38ffe6ba 100644 --- a/app/code/core/Mage/Eav/Model/Attribute/Data/Multiline.php +++ b/app/code/core/Mage/Eav/Model/Attribute/Data/Multiline.php @@ -117,20 +117,11 @@ public function outputValue($format = Mage_Eav_Model_Attribute_Data::OUTPUT_FORM $values = explode("\n", (string) $values); } $values = array_map([$this, '_applyOutputFilter'], $values); - switch ($format) { - case Mage_Eav_Model_Attribute_Data::OUTPUT_FORMAT_ARRAY: - $output = $values; - break; - case Mage_Eav_Model_Attribute_Data::OUTPUT_FORMAT_HTML: - $output = implode('
', $values); - break; - case Mage_Eav_Model_Attribute_Data::OUTPUT_FORMAT_ONELINE: - $output = implode(' ', $values); - break; - default: - $output = implode("\n", $values); - break; - } - return $output; + return match ($format) { + Mage_Eav_Model_Attribute_Data::OUTPUT_FORMAT_ARRAY => $values, + Mage_Eav_Model_Attribute_Data::OUTPUT_FORMAT_HTML => implode('
', $values), + Mage_Eav_Model_Attribute_Data::OUTPUT_FORMAT_ONELINE => implode(' ', $values), + default => implode("\n", $values), + }; } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute.php b/app/code/core/Mage/Eav/Model/Entity/Attribute.php index 9fa0dbdacec..4b2b91fe89c 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute.php @@ -56,21 +56,13 @@ class Mage_Eav_Model_Entity_Attribute extends Mage_Eav_Model_Entity_Attribute_Ab */ protected function _getDefaultBackendModel() { - switch ($this->getAttributeCode()) { - case 'created_at': - return 'eav/entity_attribute_backend_time_created'; - - case 'updated_at': - return 'eav/entity_attribute_backend_time_updated'; - - case 'store_id': - return 'eav/entity_attribute_backend_store'; - - case 'increment_id': - return 'eav/entity_attribute_backend_increment'; - } - - return parent::_getDefaultBackendModel(); + return match ($this->getAttributeCode()) { + 'created_at' => 'eav/entity_attribute_backend_time_created', + 'updated_at' => 'eav/entity_attribute_backend_time_updated', + 'store_id' => 'eav/entity_attribute_backend_store', + 'increment_id' => 'eav/entity_attribute_backend_increment', + default => parent::_getDefaultBackendModel(), + }; } /** @@ -215,34 +207,15 @@ protected function _afterSave() public function getBackendTypeByInput($type) { $field = null; - switch ($type) { - case 'text': - case 'gallery': - case 'media_image': - $field = 'varchar'; - break; - case 'image': - case 'textarea': - case 'multiselect': - $field = 'text'; - break; - - case 'date': - $field = 'datetime'; - break; - - case 'select': - case 'boolean': - $field = 'int'; - break; - - case 'price': - $field = 'decimal'; - break; - } - - return $field; + return match ($type) { + 'text', 'gallery', 'media_image' => 'varchar', + 'image', 'textarea', 'multiselect' => 'text', + 'date' => 'datetime', + 'select', 'boolean' => 'int', + 'price' => 'decimal', + default => $field, + }; } /** diff --git a/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php index 3f219ffaa4a..3d7ec9cf4fc 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php @@ -694,14 +694,10 @@ public function joinField($alias, $table, $field, $bind, $cond = null, $joinType $bindCond = $tableAlias . '.' . trim($pk) . '=' . $this->_getAttributeFieldName(trim($fk)); // process join type - switch ($joinType) { - case 'left': - $joinMethod = 'joinLeft'; - break; - - default: - $joinMethod = 'join'; - } + $joinMethod = match ($joinType) { + 'left' => 'joinLeft', + default => 'join', + }; $condArr = [$bindCond]; // add where condition if needed @@ -779,14 +775,10 @@ public function joinTable($table, $bind, $fields = null, $cond = null, $joinType $bindCond = $tableAlias . '.' . $pk . '=' . $this->_getAttributeFieldName($fk); // process join type - switch ($joinType) { - case 'left': - $joinMethod = 'joinLeft'; - break; - - default: - $joinMethod = 'join'; - } + $joinMethod = match ($joinType) { + 'left' => 'joinLeft', + default => 'join', + }; $condArr = [$bindCond]; // add where condition if needed diff --git a/app/code/core/Mage/GiftMessage/Model/Observer.php b/app/code/core/Mage/GiftMessage/Model/Observer.php index dd8f4f04897..c7cacdcfd74 100644 --- a/app/code/core/Mage/GiftMessage/Model/Observer.php +++ b/app/code/core/Mage/GiftMessage/Model/Observer.php @@ -92,23 +92,13 @@ public function checkoutEventCreateGiftMessage(Varien_Event_Observer $observer) foreach ($giftMessages as $entityId => $message) { $giftMessage = Mage::getModel('giftmessage/message'); - switch ($message['type']) { - case 'quote': - $entity = $quote; - break; - case 'quote_item': - $entity = $quote->getItemById($entityId); - break; - case 'quote_address': - $entity = $quote->getAddressById($entityId); - break; - case 'quote_address_item': - $entity = $quote->getAddressById($message['address'])->getItemById($entityId); - break; - default: - $entity = $quote; - break; - } + $entity = match ($message['type']) { + 'quote' => $quote, + 'quote_item' => $quote->getItemById($entityId), + 'quote_address' => $quote->getAddressById($entityId), + 'quote_address_item' => $quote->getAddressById($message['address'])->getItemById($entityId), + default => $quote, + }; if ($entity->getGiftMessageId()) { $giftMessage->load($entity->getGiftMessageId()); diff --git a/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Filter.php b/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Filter.php index 6f0dac21504..07423d593a7 100644 --- a/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Filter.php +++ b/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Filter.php @@ -375,23 +375,13 @@ public function decorateFilter($value, Mage_Eav_Model_Entity_Attribute $row, Var if (is_array($values) && isset($values[$row->getAttributeCode()])) { $value = $values[$row->getAttributeCode()]; } - switch (Mage_ImportExport_Model_Export::getAttributeFilterType($row)) { - case Mage_ImportExport_Model_Export::FILTER_TYPE_SELECT: - $cell = $this->_getSelectHtmlWithValue($row, $value); - break; - case Mage_ImportExport_Model_Export::FILTER_TYPE_INPUT: - $cell = $this->_getInputHtmlWithValue($row, $value); - break; - case Mage_ImportExport_Model_Export::FILTER_TYPE_DATE: - $cell = $this->_getDateFromToHtmlWithValue($row, $value); - break; - case Mage_ImportExport_Model_Export::FILTER_TYPE_NUMBER: - $cell = $this->_getNumberFromToHtmlWithValue($row, $value); - break; - default: - $cell = Mage::helper('importexport')->__('Unknown attribute filter type'); - } - return $cell; + return match (Mage_ImportExport_Model_Export::getAttributeFilterType($row)) { + Mage_ImportExport_Model_Export::FILTER_TYPE_SELECT => $this->_getSelectHtmlWithValue($row, $value), + Mage_ImportExport_Model_Export::FILTER_TYPE_INPUT => $this->_getInputHtmlWithValue($row, $value), + Mage_ImportExport_Model_Export::FILTER_TYPE_DATE => $this->_getDateFromToHtmlWithValue($row, $value), + Mage_ImportExport_Model_Export::FILTER_TYPE_NUMBER => $this->_getNumberFromToHtmlWithValue($row, $value), + default => Mage::helper('importexport')->__('Unknown attribute filter type'), + }; } /** diff --git a/app/code/core/Mage/Log/Model/Resource/Visitor/Collection.php b/app/code/core/Mage/Log/Model/Resource/Visitor/Collection.php index e8246ab906a..f30413eebe4 100644 --- a/app/code/core/Mage/Log/Model/Resource/Visitor/Collection.php +++ b/app/code/core/Mage/Log/Model/Resource/Visitor/Collection.php @@ -152,20 +152,11 @@ protected function _getGroupByDateFormat($type) */ protected function _getRangeByType($typeCode) { - switch ($typeCode) { - case 'day': - $range = 'DAY'; - break; - case 'hour': - $range = 'HOUR'; - break; - case 'minute': - default: - $range = 'MINUTE'; - break; - } - - return $range; + return match ($typeCode) { + 'day' => 'DAY', + 'hour' => 'HOUR', + default => 'MINUTE', + }; } /** diff --git a/app/code/core/Mage/Paygate/Helper/Data.php b/app/code/core/Mage/Paygate/Helper/Data.php index a3b4b9f4c34..2ffe8976ef7 100644 --- a/app/code/core/Mage/Paygate/Helper/Data.php +++ b/app/code/core/Mage/Paygate/Helper/Data.php @@ -121,20 +121,14 @@ public function getExtendedTransactionMessage( */ protected function _getOperation($requestType) { - switch ($requestType) { - case Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_AUTH_ONLY: - return $this->__('authorize'); - case Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_AUTH_CAPTURE: - return $this->__('authorize and capture'); - case Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_PRIOR_AUTH_CAPTURE: - return $this->__('capture'); - case Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_CREDIT: - return $this->__('refund'); - case Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_VOID: - return $this->__('void'); - default: - return false; - } + return match ($requestType) { + Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_AUTH_ONLY => $this->__('authorize'), + Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_AUTH_CAPTURE => $this->__('authorize and capture'), + Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_PRIOR_AUTH_CAPTURE => $this->__('capture'), + Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_CREDIT => $this->__('refund'), + Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_VOID => $this->__('void'), + default => false, + }; } /** diff --git a/app/code/core/Mage/Payment/Model/Recurring/Profile.php b/app/code/core/Mage/Payment/Model/Recurring/Profile.php index 32f764c88a3..331e86942aa 100644 --- a/app/code/core/Mage/Payment/Model/Recurring/Profile.php +++ b/app/code/core/Mage/Payment/Model/Recurring/Profile.php @@ -377,19 +377,14 @@ public function getAllPeriodUnits($withLabels = true) */ public function getPeriodUnitLabel($unit) { - switch ($unit) { - case self::PERIOD_UNIT_DAY: - return Mage::helper('payment')->__('Day'); - case self::PERIOD_UNIT_WEEK: - return Mage::helper('payment')->__('Week'); - case self::PERIOD_UNIT_SEMI_MONTH: - return Mage::helper('payment')->__('Two Weeks'); - case self::PERIOD_UNIT_MONTH: - return Mage::helper('payment')->__('Month'); - case self::PERIOD_UNIT_YEAR: - return Mage::helper('payment')->__('Year'); - } - return $unit; + return match ($unit) { + self::PERIOD_UNIT_DAY => Mage::helper('payment')->__('Day'), + self::PERIOD_UNIT_WEEK => Mage::helper('payment')->__('Week'), + self::PERIOD_UNIT_SEMI_MONTH => Mage::helper('payment')->__('Two Weeks'), + self::PERIOD_UNIT_MONTH => Mage::helper('payment')->__('Month'), + self::PERIOD_UNIT_YEAR => Mage::helper('payment')->__('Year'), + default => $unit, + }; } /** @@ -400,51 +395,30 @@ public function getPeriodUnitLabel($unit) */ public function getFieldLabel($field) { - switch ($field) { - case 'subscriber_name': - return Mage::helper('payment')->__('Subscriber Name'); - case 'start_datetime': - return Mage::helper('payment')->__('Start Date'); - case 'internal_reference_id': - return Mage::helper('payment')->__('Internal Reference ID'); - case 'schedule_description': - return Mage::helper('payment')->__('Schedule Description'); - case 'suspension_threshold': - return Mage::helper('payment')->__('Maximum Payment Failures'); - case 'bill_failed_later': - return Mage::helper('payment')->__('Auto Bill on Next Cycle'); - case 'period_unit': - return Mage::helper('payment')->__('Billing Period Unit'); - case 'period_frequency': - return Mage::helper('payment')->__('Billing Frequency'); - case 'period_max_cycles': - return Mage::helper('payment')->__('Maximum Billing Cycles'); - case 'billing_amount': - return Mage::helper('payment')->__('Billing Amount'); - case 'trial_period_unit': - return Mage::helper('payment')->__('Trial Billing Period Unit'); - case 'trial_period_frequency': - return Mage::helper('payment')->__('Trial Billing Frequency'); - case 'trial_period_max_cycles': - return Mage::helper('payment')->__('Maximum Trial Billing Cycles'); - case 'trial_billing_amount': - return Mage::helper('payment')->__('Trial Billing Amount'); - case 'currency_code': - return Mage::helper('payment')->__('Currency'); - case 'shipping_amount': - return Mage::helper('payment')->__('Shipping Amount'); - case 'tax_amount': - return Mage::helper('payment')->__('Tax Amount'); - case 'init_amount': - return Mage::helper('payment')->__('Initial Fee'); - case 'init_may_fail': - return Mage::helper('payment')->__('Allow Initial Fee Failure'); - case 'method_code': - return Mage::helper('payment')->__('Payment Method'); - case 'reference_id': - return Mage::helper('payment')->__('Payment Reference ID'); - } - return null; + return match ($field) { + 'subscriber_name' => Mage::helper('payment')->__('Subscriber Name'), + 'start_datetime' => Mage::helper('payment')->__('Start Date'), + 'internal_reference_id' => Mage::helper('payment')->__('Internal Reference ID'), + 'schedule_description' => Mage::helper('payment')->__('Schedule Description'), + 'suspension_threshold' => Mage::helper('payment')->__('Maximum Payment Failures'), + 'bill_failed_later' => Mage::helper('payment')->__('Auto Bill on Next Cycle'), + 'period_unit' => Mage::helper('payment')->__('Billing Period Unit'), + 'period_frequency' => Mage::helper('payment')->__('Billing Frequency'), + 'period_max_cycles' => Mage::helper('payment')->__('Maximum Billing Cycles'), + 'billing_amount' => Mage::helper('payment')->__('Billing Amount'), + 'trial_period_unit' => Mage::helper('payment')->__('Trial Billing Period Unit'), + 'trial_period_frequency' => Mage::helper('payment')->__('Trial Billing Frequency'), + 'trial_period_max_cycles' => Mage::helper('payment')->__('Maximum Trial Billing Cycles'), + 'trial_billing_amount' => Mage::helper('payment')->__('Trial Billing Amount'), + 'currency_code' => Mage::helper('payment')->__('Currency'), + 'shipping_amount' => Mage::helper('payment')->__('Shipping Amount'), + 'tax_amount' => Mage::helper('payment')->__('Tax Amount'), + 'init_amount' => Mage::helper('payment')->__('Initial Fee'), + 'init_may_fail' => Mage::helper('payment')->__('Allow Initial Fee Failure'), + 'method_code' => Mage::helper('payment')->__('Payment Method'), + 'reference_id' => Mage::helper('payment')->__('Payment Reference ID'), + default => null, + }; } /** @@ -455,29 +429,19 @@ public function getFieldLabel($field) */ public function getFieldComment($field) { - switch ($field) { - case 'subscriber_name': - return Mage::helper('payment')->__('Full name of the person receiving the product or service paid for by the recurring payment.'); - case 'start_datetime': - return Mage::helper('payment')->__('The date when billing for the profile begins.'); - case 'schedule_description': - return Mage::helper('payment')->__('Short description of the recurring payment. By default equals to the product name.'); - case 'suspension_threshold': - return Mage::helper('payment')->__('The number of scheduled payments that can fail before the profile is automatically suspended.'); - case 'bill_failed_later': - return Mage::helper('payment')->__('Automatically bill the outstanding balance amount in the next billing cycle (if there were failed payments).'); - case 'period_unit': - return Mage::helper('payment')->__('Unit for billing during the subscription period.'); - case 'period_frequency': - return Mage::helper('payment')->__('Number of billing periods that make up one billing cycle.'); - case 'period_max_cycles': - return Mage::helper('payment')->__('The number of billing cycles for payment period.'); - case 'init_amount': - return Mage::helper('payment')->__('Initial non-recurring payment amount due immediately upon profile creation.'); - case 'init_may_fail': - return Mage::helper('payment')->__('Whether to suspend the payment profile if the initial fee fails or add it to the outstanding balance.'); - } - return null; + return match ($field) { + 'subscriber_name' => Mage::helper('payment')->__('Full name of the person receiving the product or service paid for by the recurring payment.'), + 'start_datetime' => Mage::helper('payment')->__('The date when billing for the profile begins.'), + 'schedule_description' => Mage::helper('payment')->__('Short description of the recurring payment. By default equals to the product name.'), + 'suspension_threshold' => Mage::helper('payment')->__('The number of scheduled payments that can fail before the profile is automatically suspended.'), + 'bill_failed_later' => Mage::helper('payment')->__('Automatically bill the outstanding balance amount in the next billing cycle (if there were failed payments).'), + 'period_unit' => Mage::helper('payment')->__('Unit for billing during the subscription period.'), + 'period_frequency' => Mage::helper('payment')->__('Number of billing periods that make up one billing cycle.'), + 'period_max_cycles' => Mage::helper('payment')->__('The number of billing cycles for payment period.'), + 'init_amount' => Mage::helper('payment')->__('Initial non-recurring payment amount due immediately upon profile creation.'), + 'init_may_fail' => Mage::helper('payment')->__('Whether to suspend the payment profile if the initial fee fails or add it to the outstanding balance.'), + default => null, + }; } /** diff --git a/app/code/core/Mage/Paypal/Model/Api/ProcessableException.php b/app/code/core/Mage/Paypal/Model/Api/ProcessableException.php index 534cf185a09..4fb87dc0bca 100644 --- a/app/code/core/Mage/Paypal/Model/Api/ProcessableException.php +++ b/app/code/core/Mage/Paypal/Model/Api/ProcessableException.php @@ -34,20 +34,10 @@ class Mage_Paypal_Model_Api_ProcessableException extends Mage_Core_Exception */ public function getUserMessage() { - switch ($this->getCode()) { - case self::API_INTERNAL_ERROR: - case self::API_UNABLE_PROCESS_PAYMENT_ERROR_CODE: - $message = Mage::helper('paypal')->__("I'm sorry - but we were not able to process your payment. Please try another payment method or contact us so we can assist you."); - break; - case self::API_COUNTRY_FILTER_DECLINE: - case self::API_MAXIMUM_AMOUNT_FILTER_DECLINE: - case self::API_OTHER_FILTER_DECLINE: - $message = Mage::helper('paypal')->__("I'm sorry - but we are not able to complete your transaction. Please contact us so we can assist you."); - break; - default: - $message = $this->getMessage(); - } - - return $message; + return match ($this->getCode()) { + self::API_INTERNAL_ERROR, self::API_UNABLE_PROCESS_PAYMENT_ERROR_CODE => Mage::helper('paypal')->__("I'm sorry - but we were not able to process your payment. Please try another payment method or contact us so we can assist you."), + self::API_COUNTRY_FILTER_DECLINE, self::API_MAXIMUM_AMOUNT_FILTER_DECLINE, self::API_OTHER_FILTER_DECLINE => Mage::helper('paypal')->__("I'm sorry - but we are not able to complete your transaction. Please contact us so we can assist you."), + default => $this->getMessage(), + }; } } diff --git a/app/code/core/Mage/Paypal/Model/Config.php b/app/code/core/Mage/Paypal/Model/Config.php index 9cb2e616707..7d854599630 100644 --- a/app/code/core/Mage/Paypal/Model/Config.php +++ b/app/code/core/Mage/Paypal/Model/Config.php @@ -1363,15 +1363,12 @@ public function getRequireBillingAddressOptions() */ public function getPaymentAction() { - switch ($this->paymentAction) { - case self::PAYMENT_ACTION_AUTH: - return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE; - case self::PAYMENT_ACTION_SALE: - return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE; - case self::PAYMENT_ACTION_ORDER: - return Mage_Payment_Model_Method_Abstract::ACTION_ORDER; - } - return null; + return match ($this->paymentAction) { + self::PAYMENT_ACTION_AUTH => Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE, + self::PAYMENT_ACTION_SALE => Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE, + self::PAYMENT_ACTION_ORDER => Mage_Payment_Model_Method_Abstract::ACTION_ORDER, + default => null, + }; } /** @@ -1498,16 +1495,10 @@ public function getPayflowproCcTypesAsOptionArray() */ public static function getIsCreditCardMethod($code) { - switch ($code) { - case self::METHOD_WPP_DIRECT: - case self::METHOD_WPP_PE_DIRECT: - case self::METHOD_PAYFLOWPRO: - case self::METHOD_PAYFLOWLINK: - case self::METHOD_PAYFLOWADVANCED: - case self::METHOD_HOSTEDPRO: - return true; - } - return false; + return match ($code) { + self::METHOD_WPP_DIRECT, self::METHOD_WPP_PE_DIRECT, self::METHOD_PAYFLOWPRO, self::METHOD_PAYFLOWLINK, self::METHOD_PAYFLOWADVANCED, self::METHOD_HOSTEDPRO => true, + default => false, + }; } /** @@ -1654,13 +1645,10 @@ protected function _getSpecificConfigPath($fieldName) */ protected function _mapStandardFieldset($fieldName) { - switch ($fieldName) { - case 'line_items_summary': - case 'sandbox_flag': - return 'payment/' . self::METHOD_WPS . "/{$fieldName}"; - default: - return $this->_mapMethodFieldset($fieldName); - } + return match ($fieldName) { + 'line_items_summary', 'sandbox_flag' => 'payment/' . self::METHOD_WPS . "/{$fieldName}", + default => $this->_mapMethodFieldset($fieldName), + }; } /** @@ -1671,20 +1659,10 @@ protected function _mapStandardFieldset($fieldName) */ protected function _mapExpressFieldset($fieldName) { - switch ($fieldName) { - case 'transfer_shipping_options': - case 'solution_type': - case 'visible_on_cart': - case 'visible_on_product': - case 'require_billing_address': - case 'authorization_honor_period': - case 'order_valid_period': - case 'child_authorization_number': - case 'allow_ba_signup': - return "payment/{$this->_methodCode}/{$fieldName}"; - default: - return $this->_mapMethodFieldset($fieldName); - } + return match ($fieldName) { + 'transfer_shipping_options', 'solution_type', 'visible_on_cart', 'visible_on_product', 'require_billing_address', 'authorization_honor_period', 'order_valid_period', 'child_authorization_number', 'allow_ba_signup' => "payment/{$this->_methodCode}/{$fieldName}", + default => $this->_mapMethodFieldset($fieldName), + }; } /** @@ -1695,12 +1673,10 @@ protected function _mapExpressFieldset($fieldName) */ protected function _mapBmlFieldset($fieldName) { - switch ($fieldName) { - case 'allow_ba_signup': - return 'payment/' . self::METHOD_WPP_EXPRESS . "/{$fieldName}"; - default: - return $this->_mapExpressFieldset($fieldName); - } + return match ($fieldName) { + 'allow_ba_signup' => 'payment/' . self::METHOD_WPP_EXPRESS . "/{$fieldName}", + default => $this->_mapExpressFieldset($fieldName), + }; } /** @@ -1711,12 +1687,10 @@ protected function _mapBmlFieldset($fieldName) */ protected function _mapBmlUkFieldset($fieldName) { - switch ($fieldName) { - case 'allow_ba_signup': - return 'payment/' . self::METHOD_WPP_PE_EXPRESS . "/{$fieldName}"; - default: - return $this->_mapExpressFieldset($fieldName); - } + return match ($fieldName) { + 'allow_ba_signup' => 'payment/' . self::METHOD_WPP_PE_EXPRESS . "/{$fieldName}", + default => $this->_mapExpressFieldset($fieldName), + }; } /** @@ -1727,15 +1701,10 @@ protected function _mapBmlUkFieldset($fieldName) */ protected function _mapDirectFieldset($fieldName) { - switch ($fieldName) { - case 'useccv': - case 'centinel': - case 'centinel_is_mode_strict': - case 'centinel_api_url': - return "payment/{$this->_methodCode}/{$fieldName}"; - default: - return $this->_mapMethodFieldset($fieldName); - } + return match ($fieldName) { + 'useccv', 'centinel', 'centinel_is_mode_strict', 'centinel_api_url' => "payment/{$this->_methodCode}/{$fieldName}", + default => $this->_mapMethodFieldset($fieldName), + }; } /** @@ -1746,21 +1715,10 @@ protected function _mapDirectFieldset($fieldName) */ protected function _mapWppFieldset($fieldName) { - switch ($fieldName) { - case 'api_authentication': - case 'api_username': - case 'api_password': - case 'api_signature': - case 'api_cert': - case 'sandbox_flag': - case 'use_proxy': - case 'proxy_host': - case 'proxy_port': - case 'button_flavor': - return "paypal/wpp/{$fieldName}"; - default: - return null; - } + return match ($fieldName) { + 'api_authentication', 'api_username', 'api_password', 'api_signature', 'api_cert', 'sandbox_flag', 'use_proxy', 'proxy_host', 'proxy_port', 'button_flavor' => "paypal/wpp/{$fieldName}", + default => null, + }; } /** @@ -1782,19 +1740,10 @@ protected function _mapWpukFieldset($fieldName) ) { $pathPrefix = 'payment/' . $this->_methodCode; } - switch ($fieldName) { - case 'partner': - case 'user': - case 'vendor': - case 'pwd': - case 'sandbox_flag': - case 'use_proxy': - case 'proxy_host': - case 'proxy_port': - return $pathPrefix . '/' . $fieldName; - default: - return null; - } + return match ($fieldName) { + 'partner', 'user', 'vendor', 'pwd', 'sandbox_flag', 'use_proxy', 'proxy_host', 'proxy_port' => $pathPrefix . '/' . $fieldName, + default => null, + }; } /** @@ -1805,17 +1754,10 @@ protected function _mapWpukFieldset($fieldName) */ protected function _mapGenericStyleFieldset($fieldName) { - switch ($fieldName) { - case 'logo': - case 'page_style': - case 'paypal_hdrimg': - case 'paypal_hdrbackcolor': - case 'paypal_hdrbordercolor': - case 'paypal_payflowcolor': - return "paypal/style/{$fieldName}"; - default: - return null; - } + return match ($fieldName) { + 'logo', 'page_style', 'paypal_hdrimg', 'paypal_hdrbackcolor', 'paypal_hdrbordercolor', 'paypal_payflowcolor' => "paypal/style/{$fieldName}", + default => null, + }; } /** @@ -1826,13 +1768,10 @@ protected function _mapGenericStyleFieldset($fieldName) */ protected function _mapGeneralFieldset($fieldName) { - switch ($fieldName) { - case 'business_account': - case 'merchant_country': - return "paypal/general/{$fieldName}"; - default: - return null; - } + return match ($fieldName) { + 'business_account', 'merchant_country' => "paypal/general/{$fieldName}", + default => null, + }; } /** @@ -1846,22 +1785,10 @@ protected function _mapMethodFieldset($fieldName) if (!$this->_methodCode) { return null; } - switch ($fieldName) { - case 'active': - case 'title': - case 'payment_action': - case 'allowspecific': - case 'specificcountry': - case 'line_items_enabled': - case 'cctypes': - case 'sort_order': - case 'debug': - case 'verify_peer': - case 'mobile_optimized': - return "payment/{$this->_methodCode}/{$fieldName}"; - default: - return null; - } + return match ($fieldName) { + 'active', 'title', 'payment_action', 'allowspecific', 'specificcountry', 'line_items_enabled', 'cctypes', 'sort_order', 'debug', 'verify_peer', 'mobile_optimized' => "payment/{$this->_methodCode}/{$fieldName}", + default => null, + }; } /** diff --git a/app/code/core/Mage/Paypal/Model/Direct.php b/app/code/core/Mage/Paypal/Model/Direct.php index 18ead435263..f712543d704 100644 --- a/app/code/core/Mage/Paypal/Model/Direct.php +++ b/app/code/core/Mage/Paypal/Model/Direct.php @@ -142,14 +142,10 @@ public function isAvailable($quote = null) public function getConfigData($field, $storeId = null) { $value = null; - switch ($field) { - case 'cctypes': - $value = $this->getAllowedCcTypes(); - break; - default: - $value = $this->_pro->getConfig()->$field; - } - return $value; + return match ($field) { + 'cctypes' => $this->getAllowedCcTypes(), + default => $this->_pro->getConfig()->$field, + }; } /** diff --git a/app/code/core/Mage/Paypal/Model/Info.php b/app/code/core/Mage/Paypal/Model/Info.php index b7d2e3244f8..789ec6d9aa6 100644 --- a/app/code/core/Mage/Paypal/Model/Info.php +++ b/app/code/core/Mage/Paypal/Model/Info.php @@ -290,33 +290,18 @@ public static function isPaymentFailed(Mage_Payment_Model_Info $payment) */ public static function explainPendingReason($code) { - switch ($code) { - case 'address': - return Mage::helper('paypal')->__('Customer did not include a confirmed address.'); - case 'authorization': - case 'order': - return Mage::helper('paypal')->__('The payment is authorized but not settled.'); - case 'echeck': - return Mage::helper('paypal')->__('The payment eCheck is not yet cleared.'); - case 'intl': - return Mage::helper('paypal')->__('Merchant holds a non-U.S. account and does not have a withdrawal mechanism.'); - case 'multi-currency': // break is intentionally omitted - case 'multi_currency': // break is intentionally omitted - case 'multicurrency': - return Mage::helper('paypal')->__('The payment curency does not match any of the merchant\'s balances currency.'); - case 'paymentreview': - return Mage::helper('paypal')->__('The payment is pending while it is being reviewed by PayPal for risk.'); - case 'unilateral': - return Mage::helper('paypal')->__('The payment is pending because it was made to an email address that is not yet registered or confirmed.'); - case 'verify': - return Mage::helper('paypal')->__('The merchant account is not yet verified.'); - case 'upgrade': - return Mage::helper('paypal')->__('The payment was made via credit card. In order to receive funds merchant must upgrade account to Business or Premier status.'); - case 'none': // break is intentionally omitted - case 'other': // break is intentionally omitted - default: - return Mage::helper('paypal')->__('Unknown reason. Please contact PayPal customer service.'); - } + return match ($code) { + 'address' => Mage::helper('paypal')->__('Customer did not include a confirmed address.'), + 'authorization', 'order' => Mage::helper('paypal')->__('The payment is authorized but not settled.'), + 'echeck' => Mage::helper('paypal')->__('The payment eCheck is not yet cleared.'), + 'intl' => Mage::helper('paypal')->__('Merchant holds a non-U.S. account and does not have a withdrawal mechanism.'), + 'multi-currency', 'multi_currency', 'multicurrency' => Mage::helper('paypal')->__('The payment curency does not match any of the merchant\'s balances currency.'), + 'paymentreview' => Mage::helper('paypal')->__('The payment is pending while it is being reviewed by PayPal for risk.'), + 'unilateral' => Mage::helper('paypal')->__('The payment is pending because it was made to an email address that is not yet registered or confirmed.'), + 'verify' => Mage::helper('paypal')->__('The merchant account is not yet verified.'), + 'upgrade' => Mage::helper('paypal')->__('The payment was made via credit card. In order to receive funds merchant must upgrade account to Business or Premier status.'), + default => Mage::helper('paypal')->__('Unknown reason. Please contact PayPal customer service.'), + }; } /** @@ -361,21 +346,10 @@ public static function explainReasonCode($code) */ public static function isReversalDisputable($code) { - switch ($code) { - case 'none': - case 'other': - case 'chargeback': - case 'buyer-complaint': - case 'buyer_complaint': - case 'adjustment_reversal': - return true; - case 'guarantee': - case 'refund': - case 'chargeback_reimbursement': - case 'chargeback_settlement': - default: - return false; - } + return match ($code) { + 'none', 'other', 'chargeback', 'buyer-complaint', 'buyer_complaint', 'adjustment_reversal' => true, + default => false, + }; } /** @@ -420,37 +394,23 @@ protected function _getFullInfo(array $keys, Mage_Payment_Model_Info $payment, $ */ protected function _getLabel($key) { - switch ($key) { - case 'paypal_payer_id': - return Mage::helper('paypal')->__('Payer ID'); - case 'paypal_payer_email': - return Mage::helper('paypal')->__('Payer Email'); - case 'paypal_payer_status': - return Mage::helper('paypal')->__('Payer Status'); - case 'paypal_address_id': - return Mage::helper('paypal')->__('Payer Address ID'); - case 'paypal_address_status': - return Mage::helper('paypal')->__('Payer Address Status'); - case 'paypal_protection_eligibility': - return Mage::helper('paypal')->__('Merchant Protection Eligibility'); - case 'paypal_fraud_filters': - return Mage::helper('paypal')->__('Triggered Fraud Filters'); - case 'paypal_correlation_id': - return Mage::helper('paypal')->__('Last Correlation ID'); - case 'paypal_avs_code': - return Mage::helper('paypal')->__('Address Verification System Response'); - case 'paypal_cvv2_match': - return Mage::helper('paypal')->__('CVV2 Check Result by PayPal'); - case self::BUYER_TAX_ID: - return Mage::helper('paypal')->__('Buyer\'s Tax ID'); - case self::BUYER_TAX_ID_TYPE: - return Mage::helper('paypal')->__('Buyer\'s Tax ID Type'); - case self::CENTINEL_VPAS: - return Mage::helper('paypal')->__('PayPal/Centinel Visa Payer Authentication Service Result'); - case self::CENTINEL_ECI: - return Mage::helper('paypal')->__('PayPal/Centinel Electronic Commerce Indicator'); - } - return ''; + return match ($key) { + 'paypal_payer_id' => Mage::helper('paypal')->__('Payer ID'), + 'paypal_payer_email' => Mage::helper('paypal')->__('Payer Email'), + 'paypal_payer_status' => Mage::helper('paypal')->__('Payer Status'), + 'paypal_address_id' => Mage::helper('paypal')->__('Payer Address ID'), + 'paypal_address_status' => Mage::helper('paypal')->__('Payer Address Status'), + 'paypal_protection_eligibility' => Mage::helper('paypal')->__('Merchant Protection Eligibility'), + 'paypal_fraud_filters' => Mage::helper('paypal')->__('Triggered Fraud Filters'), + 'paypal_correlation_id' => Mage::helper('paypal')->__('Last Correlation ID'), + 'paypal_avs_code' => Mage::helper('paypal')->__('Address Verification System Response'), + 'paypal_cvv2_match' => Mage::helper('paypal')->__('CVV2 Check Result by PayPal'), + self::BUYER_TAX_ID => Mage::helper('paypal')->__('Buyer\'s Tax ID'), + self::BUYER_TAX_ID_TYPE => Mage::helper('paypal')->__('Buyer\'s Tax ID Type'), + self::CENTINEL_VPAS => Mage::helper('paypal')->__('PayPal/Centinel Visa Payer Authentication Service Result'), + self::CENTINEL_ECI => Mage::helper('paypal')->__('PayPal/Centinel Electronic Commerce Indicator'), + default => '', + }; } /** @@ -510,59 +470,35 @@ protected function _getValue($value, $key) */ protected function _getAvsLabel($value) { - switch ($value) { - // Visa, MasterCard, Discover and American Express - case 'A': - case 'YN': - return Mage::helper('paypal')->__('Matched Address only (no ZIP)'); - case 'B': // international "A" - return Mage::helper('paypal')->__('Matched Address only (no ZIP). International'); - case 'N': - return Mage::helper('paypal')->__('No Details matched'); - case 'C': // international "N" - return Mage::helper('paypal')->__('No Details matched. International'); - case 'X': - return Mage::helper('paypal')->__('Exact Match. Address and nine-digit ZIP code'); - case 'D': // international "X" - return Mage::helper('paypal')->__('Exact Match. Address and Postal Code. International'); - case 'F': // UK-specific "X" - return Mage::helper('paypal')->__('Exact Match. Address and Postal Code. UK-specific'); - case 'E': - return Mage::helper('paypal')->__('N/A. Not allowed for MOTO (Internet/Phone) transactions'); - case 'G': - return Mage::helper('paypal')->__('N/A. Global Unavailable'); - case 'I': - return Mage::helper('paypal')->__('N/A. International Unavailable'); - case 'Z': - case 'NY': - return Mage::helper('paypal')->__('Matched five-digit ZIP only (no Address)'); - case 'P': // international "Z" - case 'NY': - return Mage::helper('paypal')->__('Matched Postal Code only (no Address)'); - case 'R': - return Mage::helper('paypal')->__('N/A. Retry'); - case 'S': - return Mage::helper('paypal')->__('N/A. Service not Supported'); - case 'U': - return Mage::helper('paypal')->__('N/A. Unavailable'); - case 'W': - return Mage::helper('paypal')->__('Matched whole nine-didgit ZIP (no Address)'); - case 'Y': - return Mage::helper('paypal')->__('Yes. Matched Address and five-didgit ZIP'); - // Maestro and Solo - case '0': - return Mage::helper('paypal')->__('All the address information matched'); - case '1': - return Mage::helper('paypal')->__('None of the address information matched'); - case '2': - return Mage::helper('paypal')->__('Part of the address information matched'); - case '3': - return Mage::helper('paypal')->__('N/A. The merchant did not provide AVS information'); - case '4': - return Mage::helper('paypal')->__('N/A. Address not checked, or acquirer had no response. Service not available'); - default: - return $value; - } + return match ($value) { + 'A', 'YN' => Mage::helper('paypal')->__('Matched Address only (no ZIP)'), + // international "A" + 'B' => Mage::helper('paypal')->__('Matched Address only (no ZIP). International'), + 'N' => Mage::helper('paypal')->__('No Details matched'), + // international "N" + 'C' => Mage::helper('paypal')->__('No Details matched. International'), + 'X' => Mage::helper('paypal')->__('Exact Match. Address and nine-digit ZIP code'), + // international "X" + 'D' => Mage::helper('paypal')->__('Exact Match. Address and Postal Code. International'), + // UK-specific "X" + 'F' => Mage::helper('paypal')->__('Exact Match. Address and Postal Code. UK-specific'), + 'E' => Mage::helper('paypal')->__('N/A. Not allowed for MOTO (Internet/Phone) transactions'), + 'G' => Mage::helper('paypal')->__('N/A. Global Unavailable'), + 'I' => Mage::helper('paypal')->__('N/A. International Unavailable'), + 'Z', 'NY' => Mage::helper('paypal')->__('Matched five-digit ZIP only (no Address)'), + 'P', 'NY' => Mage::helper('paypal')->__('Matched Postal Code only (no Address)'), + 'R' => Mage::helper('paypal')->__('N/A. Retry'), + 'S' => Mage::helper('paypal')->__('N/A. Service not Supported'), + 'U' => Mage::helper('paypal')->__('N/A. Unavailable'), + 'W' => Mage::helper('paypal')->__('Matched whole nine-didgit ZIP (no Address)'), + 'Y' => Mage::helper('paypal')->__('Yes. Matched Address and five-didgit ZIP'), + '0' => Mage::helper('paypal')->__('All the address information matched'), + '1' => Mage::helper('paypal')->__('None of the address information matched'), + '2' => Mage::helper('paypal')->__('Part of the address information matched'), + '3' => Mage::helper('paypal')->__('N/A. The merchant did not provide AVS information'), + '4' => Mage::helper('paypal')->__('N/A. Address not checked, or acquirer had no response. Service not available'), + default => $value, + }; } /** @@ -574,34 +510,20 @@ protected function _getAvsLabel($value) */ protected function _getCvv2Label($value) { - switch ($value) { - // Visa, MasterCard, Discover and American Express - case 'M': - return Mage::helper('paypal')->__('Matched (CVV2CSC)'); - case 'N': - return Mage::helper('paypal')->__('No match'); - case 'P': - return Mage::helper('paypal')->__('N/A. Not processed'); - case 'S': - return Mage::helper('paypal')->__('N/A. Service not supported'); - case 'U': - return Mage::helper('paypal')->__('N/A. Service not available'); - case 'X': - return Mage::helper('paypal')->__('N/A. No response'); - // Maestro and Solo - case '0': - return Mage::helper('paypal')->__('Matched (CVV2)'); - case '1': - return Mage::helper('paypal')->__('No match'); - case '2': - return Mage::helper('paypal')->__('N/A. The merchant has not implemented CVV2 code handling'); - case '3': - return Mage::helper('paypal')->__('N/A. Merchant has indicated that CVV2 is not present on card'); - case '4': - return Mage::helper('paypal')->__('N/A. Service not available'); - default: - return $value; - } + return match ($value) { + 'M' => Mage::helper('paypal')->__('Matched (CVV2CSC)'), + 'N' => Mage::helper('paypal')->__('No match'), + 'P' => Mage::helper('paypal')->__('N/A. Not processed'), + 'S' => Mage::helper('paypal')->__('N/A. Service not supported'), + 'U' => Mage::helper('paypal')->__('N/A. Service not available'), + 'X' => Mage::helper('paypal')->__('N/A. No response'), + '0' => Mage::helper('paypal')->__('Matched (CVV2)'), + '1' => Mage::helper('paypal')->__('No match'), + '2' => Mage::helper('paypal')->__('N/A. The merchant has not implemented CVV2 code handling'), + '3' => Mage::helper('paypal')->__('N/A. Merchant has indicated that CVV2 is not present on card'), + '4' => Mage::helper('paypal')->__('N/A. Service not available'), + default => $value, + }; } /** @@ -613,29 +535,14 @@ protected function _getCvv2Label($value) */ private function _getCentinelVpasLabel($value) { - switch ($value) { - case '2': - case 'D': - return Mage::helper('paypal')->__('Authenticated, Good Result'); - case '1': - return Mage::helper('paypal')->__('Authenticated, Bad Result'); - case '3': - case '6': - case '8': - case 'A': - case 'C': - return Mage::helper('paypal')->__('Attempted Authentication, Good Result'); - case '4': - case '7': - case '9': - return Mage::helper('paypal')->__('Attempted Authentication, Bad Result'); - case '': - case '0': - case 'B': - return Mage::helper('paypal')->__('No Liability Shift'); - default: - return $value; - } + return match ($value) { + '2', 'D' => Mage::helper('paypal')->__('Authenticated, Good Result'), + '1' => Mage::helper('paypal')->__('Authenticated, Bad Result'), + '3', '6', '8', 'A', 'C' => Mage::helper('paypal')->__('Attempted Authentication, Good Result'), + '4', '7', '9' => Mage::helper('paypal')->__('Attempted Authentication, Bad Result'), + '', '0', 'B' => Mage::helper('paypal')->__('No Liability Shift'), + default => $value, + }; } /** @@ -647,17 +554,11 @@ private function _getCentinelVpasLabel($value) */ private function _getCentinelEciLabel($value) { - switch ($value) { - case '01': - case '07': - return Mage::helper('paypal')->__('Merchant Liability'); - case '02': - case '05': - case '06': - return Mage::helper('paypal')->__('Issuer Liability'); - default: - return $value; - } + return match ($value) { + '01', '07' => Mage::helper('paypal')->__('Merchant Liability'), + '02', '05', '06' => Mage::helper('paypal')->__('Issuer Liability'), + default => $value, + }; } /** @@ -669,14 +570,10 @@ private function _getCentinelEciLabel($value) protected function _getBuyerIdTypeValue($code) { $value = ''; - switch ($code) { - case self::BUYER_TAX_ID_TYPE_CNPJ: - $value = Mage::helper('paypal')->__('CNPJ'); - break; - case self::BUYER_TAX_ID_TYPE_CPF: - $value = Mage::helper('paypal')->__('CPF'); - break; - } - return $value; + return match ($code) { + self::BUYER_TAX_ID_TYPE_CNPJ => Mage::helper('paypal')->__('CNPJ'), + self::BUYER_TAX_ID_TYPE_CPF => Mage::helper('paypal')->__('CPF'), + default => $value, + }; } } diff --git a/app/code/core/Mage/Paypal/Model/Ipn.php b/app/code/core/Mage/Paypal/Model/Ipn.php index 1144174ada1..7c6a5af4b63 100644 --- a/app/code/core/Mage/Paypal/Model/Ipn.php +++ b/app/code/core/Mage/Paypal/Model/Ipn.php @@ -264,21 +264,11 @@ protected function _processOrder() try { // Handle payment_status $transactionType = $this->_request['txn_type'] ?? null; - switch ($transactionType) { - // handle new case created - case Mage_Paypal_Model_Info::TXN_TYPE_NEW_CASE: - $this->_registerDispute(); - break; - - // handle new adjustment is created - case Mage_Paypal_Model_Info::TXN_TYPE_ADJUSTMENT: - $this->_registerAdjustment(); - break; - - //handle new transaction created - default: - $this->_registerTransaction(); - } + match ($transactionType) { + Mage_Paypal_Model_Info::TXN_TYPE_NEW_CASE => $this->_registerDispute(), + Mage_Paypal_Model_Info::TXN_TYPE_ADJUSTMENT => $this->_registerAdjustment(), + default => $this->_registerTransaction(), + }; } catch (Mage_Core_Exception $e) { $comment = $this->_createIpnComment(Mage::helper('paypal')->__('Note: %s', $e->getMessage()), true); $comment->save(); @@ -330,50 +320,18 @@ protected function _registerTransaction() try { // Handle payment_status $paymentStatus = $this->_filterPaymentStatus($this->_request['payment_status']); - switch ($paymentStatus) { - // paid - case Mage_Paypal_Model_Info::PAYMENTSTATUS_COMPLETED: - $this->_registerPaymentCapture(true); - break; - - // the held payment was denied on paypal side - case Mage_Paypal_Model_Info::PAYMENTSTATUS_DENIED: - $this->_registerPaymentDenial(); - break; - - // customer attempted to pay via bank account, but failed - case Mage_Paypal_Model_Info::PAYMENTSTATUS_FAILED: - // cancel order - $this->_registerPaymentFailure(); - break; - - // payment was obtained, but money were not captured yet - case Mage_Paypal_Model_Info::PAYMENTSTATUS_PENDING: - $this->_registerPaymentPending(); - break; - - case Mage_Paypal_Model_Info::PAYMENTSTATUS_PROCESSED: - $this->_registerMasspaymentsSuccess(); - break; - - case Mage_Paypal_Model_Info::PAYMENTSTATUS_REVERSED:// break is intentionally omitted - case Mage_Paypal_Model_Info::PAYMENTSTATUS_UNREVERSED: - $this->_registerPaymentReversal(); - break; - - case Mage_Paypal_Model_Info::PAYMENTSTATUS_REFUNDED: - $this->_registerPaymentRefund(); - break; - - // authorization expire/void - case Mage_Paypal_Model_Info::PAYMENTSTATUS_EXPIRED: // break is intentionally omitted - case Mage_Paypal_Model_Info::PAYMENTSTATUS_VOIDED: - $this->_registerPaymentVoid(); - break; - - default: - throw new Exception("Cannot handle payment status '{$paymentStatus}'."); - } + match ($paymentStatus) { + Mage_Paypal_Model_Info::PAYMENTSTATUS_COMPLETED => $this->_registerPaymentCapture(true), + Mage_Paypal_Model_Info::PAYMENTSTATUS_DENIED => $this->_registerPaymentDenial(), + // cancel order + Mage_Paypal_Model_Info::PAYMENTSTATUS_FAILED => $this->_registerPaymentFailure(), + Mage_Paypal_Model_Info::PAYMENTSTATUS_PENDING => $this->_registerPaymentPending(), + Mage_Paypal_Model_Info::PAYMENTSTATUS_PROCESSED => $this->_registerMasspaymentsSuccess(), + Mage_Paypal_Model_Info::PAYMENTSTATUS_REVERSED, Mage_Paypal_Model_Info::PAYMENTSTATUS_UNREVERSED => $this->_registerPaymentReversal(), + Mage_Paypal_Model_Info::PAYMENTSTATUS_REFUNDED => $this->_registerPaymentRefund(), + Mage_Paypal_Model_Info::PAYMENTSTATUS_EXPIRED, Mage_Paypal_Model_Info::PAYMENTSTATUS_VOIDED => $this->_registerPaymentVoid(), + default => throw new Exception("Cannot handle payment status '{$paymentStatus}'."), + }; } catch (Mage_Core_Exception $e) { $comment = $this->_createIpnComment(Mage::helper('paypal')->__('Note: %s', $e->getMessage()), true); $comment->save(); @@ -393,15 +351,10 @@ protected function _processRecurringProfile() // handle payment_status $paymentStatus = $this->_filterPaymentStatus($this->_request['payment_status']); - switch ($paymentStatus) { - // paid - case Mage_Paypal_Model_Info::PAYMENTSTATUS_COMPLETED: - $this->_registerRecurringProfilePaymentCapture(); - break; - - default: - throw new Exception("Cannot handle payment status '{$paymentStatus}'."); - } + match ($paymentStatus) { + Mage_Paypal_Model_Info::PAYMENTSTATUS_COMPLETED => $this->_registerRecurringProfilePaymentCapture(), + default => throw new Exception("Cannot handle payment status '{$paymentStatus}'."), + }; } catch (Mage_Core_Exception $e) { throw $e; } @@ -775,30 +728,19 @@ protected function _importPaymentInformation() */ protected function _filterPaymentStatus($ipnPaymentStatus) { - switch ($ipnPaymentStatus) { - case 'Created': // break is intentionally omitted - case 'Completed': - return Mage_Paypal_Model_Info::PAYMENTSTATUS_COMPLETED; - case 'Denied': - return Mage_Paypal_Model_Info::PAYMENTSTATUS_DENIED; - case 'Expired': - return Mage_Paypal_Model_Info::PAYMENTSTATUS_EXPIRED; - case 'Failed': - return Mage_Paypal_Model_Info::PAYMENTSTATUS_FAILED; - case 'Pending': - return Mage_Paypal_Model_Info::PAYMENTSTATUS_PENDING; - case 'Refunded': - return Mage_Paypal_Model_Info::PAYMENTSTATUS_REFUNDED; - case 'Reversed': - return Mage_Paypal_Model_Info::PAYMENTSTATUS_REVERSED; - case 'Canceled_Reversal': - return Mage_Paypal_Model_Info::PAYMENTSTATUS_UNREVERSED; - case 'Processed': - return Mage_Paypal_Model_Info::PAYMENTSTATUS_PROCESSED; - case 'Voided': - return Mage_Paypal_Model_Info::PAYMENTSTATUS_VOIDED; - } - return ''; + return match ($ipnPaymentStatus) { + 'Created', 'Completed' => Mage_Paypal_Model_Info::PAYMENTSTATUS_COMPLETED, + 'Denied' => Mage_Paypal_Model_Info::PAYMENTSTATUS_DENIED, + 'Expired' => Mage_Paypal_Model_Info::PAYMENTSTATUS_EXPIRED, + 'Failed' => Mage_Paypal_Model_Info::PAYMENTSTATUS_FAILED, + 'Pending' => Mage_Paypal_Model_Info::PAYMENTSTATUS_PENDING, + 'Refunded' => Mage_Paypal_Model_Info::PAYMENTSTATUS_REFUNDED, + 'Reversed' => Mage_Paypal_Model_Info::PAYMENTSTATUS_REVERSED, + 'Canceled_Reversal' => Mage_Paypal_Model_Info::PAYMENTSTATUS_UNREVERSED, + 'Processed' => Mage_Paypal_Model_Info::PAYMENTSTATUS_PROCESSED, + 'Voided' => Mage_Paypal_Model_Info::PAYMENTSTATUS_VOIDED, + default => '', + }; // documented in NVP, but not documented in IPN: //Mage_Paypal_Model_Info::PAYMENTSTATUS_NONE //Mage_Paypal_Model_Info::PAYMENTSTATUS_INPROGRESS diff --git a/app/code/core/Mage/Paypal/Model/Payflow/Request.php b/app/code/core/Mage/Paypal/Model/Payflow/Request.php index d5641a90836..2c7169051ea 100644 --- a/app/code/core/Mage/Paypal/Model/Payflow/Request.php +++ b/app/code/core/Mage/Paypal/Model/Payflow/Request.php @@ -29,19 +29,12 @@ public function __call($method, $args) if (isset($args[0]) && (strstr($args[0], '=') || strstr($args[0], '&'))) { $key .= '[' . strlen($args[0]) . ']'; } - switch (substr($method, 0, 3)) { - case 'get': - return $this->getData($key, $args[0] ?? null); - - case 'set': - return $this->setData($key, $args[0] ?? null); - - case 'uns': - return $this->unsetData($key); - - case 'has': - return isset($this->_data[$key]); - } - throw new Varien_Exception('Invalid method ' . get_class($this) . '::' . $method . '(' . print_r($args, true) . ')'); + return match (substr($method, 0, 3)) { + 'get' => $this->getData($key, $args[0] ?? null), + 'set' => $this->setData($key, $args[0] ?? null), + 'uns' => $this->unsetData($key), + 'has' => isset($this->_data[$key]), + default => throw new Varien_Exception('Invalid method ' . get_class($this) . '::' . $method . '(' . print_r($args, true) . ')'), + }; } } diff --git a/app/code/core/Mage/Paypal/Model/Payflowlink.php b/app/code/core/Mage/Paypal/Model/Payflowlink.php index efe87412d74..c2703243e65 100644 --- a/app/code/core/Mage/Paypal/Model/Payflowlink.php +++ b/app/code/core/Mage/Paypal/Model/Payflowlink.php @@ -465,13 +465,11 @@ protected function _buildBasicRequest(Varien_Object $payment) */ protected function _getTrxTokenType() { - switch ($this->getConfigData('payment_action')) { - case Mage_Paypal_Model_Config::PAYMENT_ACTION_AUTH: - return self::TRXTYPE_AUTH_ONLY; - case Mage_Paypal_Model_Config::PAYMENT_ACTION_SALE: - return self::TRXTYPE_SALE; - } - return ''; + return match ($this->getConfigData('payment_action')) { + Mage_Paypal_Model_Config::PAYMENT_ACTION_AUTH => self::TRXTYPE_AUTH_ONLY, + Mage_Paypal_Model_Config::PAYMENT_ACTION_SALE => self::TRXTYPE_SALE, + default => '', + }; } /** diff --git a/app/code/core/Mage/Paypal/Model/Payflowpro.php b/app/code/core/Mage/Paypal/Model/Payflowpro.php index 5a1e7432f96..1bc12df748c 100644 --- a/app/code/core/Mage/Paypal/Model/Payflowpro.php +++ b/app/code/core/Mage/Paypal/Model/Payflowpro.php @@ -119,13 +119,11 @@ public function isAvailable($quote = null) */ public function getConfigPaymentAction() { - switch ($this->getConfigData('payment_action')) { - case Mage_Paypal_Model_Config::PAYMENT_ACTION_AUTH: - return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE; - case Mage_Paypal_Model_Config::PAYMENT_ACTION_SALE: - return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE; - } - return ''; + return match ($this->getConfigData('payment_action')) { + Mage_Paypal_Model_Config::PAYMENT_ACTION_AUTH => Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE, + Mage_Paypal_Model_Config::PAYMENT_ACTION_SALE => Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE, + default => '', + }; } /** diff --git a/app/code/core/Mage/Paypal/Model/Report/Settlement.php b/app/code/core/Mage/Paypal/Model/Report/Settlement.php index 241e6563299..702569d8cf6 100644 --- a/app/code/core/Mage/Paypal/Model/Report/Settlement.php +++ b/app/code/core/Mage/Paypal/Model/Report/Settlement.php @@ -320,40 +320,24 @@ public function getRows() */ public function getFieldLabel($field) { - switch ($field) { - case 'report_date': - return Mage::helper('paypal')->__('Report Date'); - case 'account_id': - return Mage::helper('paypal')->__('Merchant Account'); - case 'transaction_id': - return Mage::helper('paypal')->__('Transaction ID'); - case 'invoice_id': - return Mage::helper('paypal')->__('Invoice ID'); - case 'paypal_reference_id': - return Mage::helper('paypal')->__('PayPal Reference ID'); - case 'paypal_reference_id_type': - return Mage::helper('paypal')->__('PayPal Reference ID Type'); - case 'transaction_event_code': - return Mage::helper('paypal')->__('Event Code'); - case 'transaction_event': - return Mage::helper('paypal')->__('Event'); - case 'transaction_initiation_date': - return Mage::helper('paypal')->__('Initiation Date'); - case 'transaction_completion_date': - return Mage::helper('paypal')->__('Completion Date'); - case 'transaction_debit_or_credit': - return Mage::helper('paypal')->__('Debit or Credit'); - case 'gross_transaction_amount': - return Mage::helper('paypal')->__('Gross Amount'); - case 'fee_debit_or_credit': - return Mage::helper('paypal')->__('Fee Debit or Credit'); - case 'fee_amount': - return Mage::helper('paypal')->__('Fee Amount'); - case 'custom_field': - return Mage::helper('paypal')->__('Custom'); - default: - return $field; - } + return match ($field) { + 'report_date' => Mage::helper('paypal')->__('Report Date'), + 'account_id' => Mage::helper('paypal')->__('Merchant Account'), + 'transaction_id' => Mage::helper('paypal')->__('Transaction ID'), + 'invoice_id' => Mage::helper('paypal')->__('Invoice ID'), + 'paypal_reference_id' => Mage::helper('paypal')->__('PayPal Reference ID'), + 'paypal_reference_id_type' => Mage::helper('paypal')->__('PayPal Reference ID Type'), + 'transaction_event_code' => Mage::helper('paypal')->__('Event Code'), + 'transaction_event' => Mage::helper('paypal')->__('Event'), + 'transaction_initiation_date' => Mage::helper('paypal')->__('Initiation Date'), + 'transaction_completion_date' => Mage::helper('paypal')->__('Completion Date'), + 'transaction_debit_or_credit' => Mage::helper('paypal')->__('Debit or Credit'), + 'gross_transaction_amount' => Mage::helper('paypal')->__('Gross Amount'), + 'fee_debit_or_credit' => Mage::helper('paypal')->__('Fee Debit or Credit'), + 'fee_amount' => Mage::helper('paypal')->__('Fee Amount'), + 'custom_field' => Mage::helper('paypal')->__('Custom'), + default => $field, + }; } /** diff --git a/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php b/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php index 69df8641ea3..d5059179d9b 100644 --- a/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php +++ b/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php @@ -107,14 +107,10 @@ protected function _initAction() protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); - switch ($action) { - case 'index': - case 'details': - return Mage::getSingleton('admin/session')->isAllowed('report/salesroot/paypal_settlement_reports/view'); - case 'fetch': - return Mage::getSingleton('admin/session')->isAllowed('report/salesroot/paypal_settlement_reports/fetch'); - default: - return Mage::getSingleton('admin/session')->isAllowed('report/salesroot/paypal_settlement_reports'); - } + return match ($action) { + 'index', 'details' => Mage::getSingleton('admin/session')->isAllowed('report/salesroot/paypal_settlement_reports/view'), + 'fetch' => Mage::getSingleton('admin/session')->isAllowed('report/salesroot/paypal_settlement_reports/fetch'), + default => Mage::getSingleton('admin/session')->isAllowed('report/salesroot/paypal_settlement_reports'), + }; } } diff --git a/app/code/core/Mage/PaypalUk/Model/Api/Nvp.php b/app/code/core/Mage/PaypalUk/Model/Api/Nvp.php index 60952e1474f..e3a9f7aad0c 100644 --- a/app/code/core/Mage/PaypalUk/Model/Api/Nvp.php +++ b/app/code/core/Mage/PaypalUk/Model/Api/Nvp.php @@ -411,15 +411,12 @@ protected function _addMethodToRequest($methodName, $request) */ protected function _getPaypalUkActionName($methodName) { - switch ($methodName) { - case Mage_Paypal_Model_Api_Nvp::SET_EXPRESS_CHECKOUT: - return self::EXPRESS_SET; - case Mage_Paypal_Model_Api_Nvp::GET_EXPRESS_CHECKOUT_DETAILS: - return self::EXPRESS_GET; - case Mage_Paypal_Model_Api_Nvp::DO_EXPRESS_CHECKOUT_PAYMENT: - return self::EXPRESS_DO_PAYMENT; - } - return null; + return match ($methodName) { + Mage_Paypal_Model_Api_Nvp::SET_EXPRESS_CHECKOUT => self::EXPRESS_SET, + Mage_Paypal_Model_Api_Nvp::GET_EXPRESS_CHECKOUT_DETAILS => self::EXPRESS_GET, + Mage_Paypal_Model_Api_Nvp::DO_EXPRESS_CHECKOUT_PAYMENT => self::EXPRESS_DO_PAYMENT, + default => null, + }; } /** diff --git a/app/code/core/Mage/Reports/Model/Resource/Event.php b/app/code/core/Mage/Reports/Model/Resource/Event.php index 508d96f399a..5d0786f764d 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Event.php +++ b/app/code/core/Mage/Reports/Model/Resource/Event.php @@ -115,17 +115,11 @@ public function getCurrentStoreIds(?array $predefinedStoreIds = null) } } } else { // get all stores, required by configuration in current store scope - switch (Mage::getStoreConfig('catalog/recently_products/scope')) { - case 'website': - $resourceStore = Mage::app()->getStore()->getWebsite()->getStores(); - break; - case 'group': - $resourceStore = Mage::app()->getStore()->getGroup()->getStores(); - break; - default: - $resourceStore = [Mage::app()->getStore()]; - break; - } + $resourceStore = match (Mage::getStoreConfig('catalog/recently_products/scope')) { + 'website' => Mage::app()->getStore()->getWebsite()->getStores(), + 'group' => Mage::app()->getStore()->getGroup()->getStores(), + default => [Mage::app()->getStore()], + }; foreach ($resourceStore as $store) { $stores[] = $store->getId(); diff --git a/app/code/core/Mage/Reports/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/Reports/Model/Resource/Helper/Mysql4.php index fac92c76cb9..9836bade3d5 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Helper/Mysql4.php +++ b/app/code/core/Mage/Reports/Model/Resource/Helper/Mysql4.php @@ -43,17 +43,11 @@ public function updateReportRatingPos($type, $column, $mainTable, $aggregationTa $ratingSubSelect = $adapter->select(); $ratingSelect = $adapter->select(); - switch ($type) { - case 'year': - $periodCol = $adapter->getDateFormatSql('t.period', '%Y-01-01'); - break; - case 'month': - $periodCol = $adapter->getDateFormatSql('t.period', '%Y-%m-01'); - break; - default: - $periodCol = 't.period'; - break; - } + $periodCol = match ($type) { + 'year' => $adapter->getDateFormatSql('t.period', '%Y-01-01'), + 'month' => $adapter->getDateFormatSql('t.period', '%Y-%m-01'), + default => 't.period', + }; $columns = [ 'period' => 't.period', diff --git a/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php index 918d31672f0..2c18610845c 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php +++ b/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php @@ -219,28 +219,14 @@ protected function _prepareSummaryAggregated($range, $customStart, $customEnd) */ protected function _getRangeExpression($range) { - switch ($range) { - case Mage_Reports_Helper_Data::PERIOD_24_HOURS: - $expression = $this->getConnection()->getConcatSql([ - $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m-%d %H:'), - $this->getConnection()->quote('00'), - ]); - break; - case Mage_Reports_Helper_Data::PERIOD_7_DAYS: - case Mage_Reports_Helper_Data::PERIOD_1_MONTH: - case Mage_Reports_Helper_Data::PERIOD_3_MONTHS: - case Mage_Reports_Helper_Data::PERIOD_6_MONTHS: - $expression = $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m-%d'); - break; - case Mage_Reports_Helper_Data::PERIOD_1_YEAR: - case Mage_Reports_Helper_Data::PERIOD_2_YEARS: - case Mage_Reports_Helper_Data::PERIOD_CUSTOM: - default: - $expression = $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m'); - break; - } - - return $expression; + return match ($range) { + Mage_Reports_Helper_Data::PERIOD_24_HOURS => $this->getConnection()->getConcatSql([ + $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m-%d %H:'), + $this->getConnection()->quote('00'), + ]), + Mage_Reports_Helper_Data::PERIOD_7_DAYS, Mage_Reports_Helper_Data::PERIOD_1_MONTH, Mage_Reports_Helper_Data::PERIOD_3_MONTHS, Mage_Reports_Helper_Data::PERIOD_6_MONTHS => $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m-%d'), + default => $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m'), + }; } /** diff --git a/app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php b/app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php index 642e2ed5e85..919a997e09f 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php @@ -343,22 +343,13 @@ public function getInputType() if ($this->getAttributeObject()->getAttributeCode() == 'category_ids') { return 'category'; } - switch ($this->getAttributeObject()->getFrontendInput()) { - case 'select': - return 'select'; - - case 'multiselect': - return 'multiselect'; - - case 'date': - return 'date'; - - case 'boolean': - return 'boolean'; - - default: - return 'string'; - } + return match ($this->getAttributeObject()->getFrontendInput()) { + 'select' => 'select', + 'multiselect' => 'multiselect', + 'date' => 'date', + 'boolean' => 'boolean', + default => 'string', + }; } /** @@ -374,20 +365,12 @@ public function getValueElementType() if (!is_object($this->getAttributeObject())) { return 'text'; } - switch ($this->getAttributeObject()->getFrontendInput()) { - case 'select': - case 'boolean': - return 'select'; - - case 'multiselect': - return 'multiselect'; - - case 'date': - return 'date'; - - default: - return 'text'; - } + return match ($this->getAttributeObject()->getFrontendInput()) { + 'select', 'boolean' => 'select', + 'multiselect' => 'multiselect', + 'date' => 'date', + default => 'text', + }; } /** diff --git a/app/code/core/Mage/Sales/Model/Billing/Agreement.php b/app/code/core/Mage/Sales/Model/Billing/Agreement.php index 954a854c384..51d7267f7f0 100644 --- a/app/code/core/Mage/Sales/Model/Billing/Agreement.php +++ b/app/code/core/Mage/Sales/Model/Billing/Agreement.php @@ -98,13 +98,11 @@ protected function _afterSave() */ public function getStatusLabel() { - switch ($this->getStatus()) { - case self::STATUS_ACTIVE: - return Mage::helper('sales')->__('Active'); - case self::STATUS_CANCELED: - return Mage::helper('sales')->__('Canceled'); - } - return ''; + return match ($this->getStatus()) { + self::STATUS_ACTIVE => Mage::helper('sales')->__('Active'), + self::STATUS_CANCELED => Mage::helper('sales')->__('Canceled'), + default => '', + }; } /** diff --git a/app/code/core/Mage/Sales/Model/Observer.php b/app/code/core/Mage/Sales/Model/Observer.php index 1d15733117d..3da503b26ee 100644 --- a/app/code/core/Mage/Sales/Model/Observer.php +++ b/app/code/core/Mage/Sales/Model/Observer.php @@ -371,14 +371,10 @@ protected function _getVatRequiredSalesAddress($salesModel, $store = null) { $configAddressType = Mage::helper('customer/address')->getTaxCalculationAddressType($store); $requiredAddress = null; - switch ($configAddressType) { - case Mage_Customer_Model_Address_Abstract::TYPE_SHIPPING: - $requiredAddress = $salesModel->getShippingAddress(); - break; - default: - $requiredAddress = $salesModel->getBillingAddress(); - } - return $requiredAddress; + return match ($configAddressType) { + Mage_Customer_Model_Address_Abstract::TYPE_SHIPPING => $salesModel->getShippingAddress(), + default => $salesModel->getBillingAddress(), + }; } /** @@ -391,14 +387,10 @@ protected function _getVatRequiredCustomerAddress(Mage_Customer_Model_Customer $ { $configAddressType = Mage::helper('customer/address')->getTaxCalculationAddressType($store); $requiredAddress = null; - switch ($configAddressType) { - case Mage_Customer_Model_Address_Abstract::TYPE_SHIPPING: - $requiredAddress = $customer->getDefaultShipping(); - break; - default: - $requiredAddress = $customer->getDefaultBilling(); - } - return $requiredAddress; + return match ($configAddressType) { + Mage_Customer_Model_Address_Abstract::TYPE_SHIPPING => $customer->getDefaultShipping(), + default => $customer->getDefaultBilling(), + }; } /** diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php index fed4b7e7872..3bf07ef1bf2 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php @@ -907,17 +907,11 @@ public function drawLineBlocks(Zend_Pdf_Page $page, array $draw, array $pageSett $page->setFont($font, $fontSize); } else { $fontStyle = empty($column['font']) ? 'regular' : $column['font']; - switch ($fontStyle) { - case 'bold': - $font = $this->_setFontBold($page, $fontSize); - break; - case 'italic': - $font = $this->_setFontItalic($page, $fontSize); - break; - default: - $font = $this->_setFontRegular($page, $fontSize); - break; - } + $font = match ($fontStyle) { + 'bold' => $this->_setFontBold($page, $fontSize), + 'italic' => $this->_setFontItalic($page, $fontSize), + default => $this->_setFontRegular($page, $fontSize), + }; } if (!is_array($column['text'])) { diff --git a/app/code/core/Mage/Sales/Model/Recurring/Profile.php b/app/code/core/Mage/Sales/Model/Recurring/Profile.php index 2d0b2702a9b..89b1222eae4 100644 --- a/app/code/core/Mage/Sales/Model/Recurring/Profile.php +++ b/app/code/core/Mage/Sales/Model/Recurring/Profile.php @@ -415,18 +415,13 @@ public function importQuoteItem(Mage_Sales_Model_Quote_Item_Abstract $item) */ public function getFieldLabel($field) { - switch ($field) { - case 'order_item_id': - return Mage::helper('sales')->__('Purchased Item'); - case 'state': - return Mage::helper('sales')->__('Profile State'); - case 'created_at': - return Mage::helper('adminhtml')->__('Created At'); - case 'updated_at': - return Mage::helper('adminhtml')->__('Updated At'); - default: - return parent::getFieldLabel($field); - } + return match ($field) { + 'order_item_id' => Mage::helper('sales')->__('Purchased Item'), + 'state' => Mage::helper('sales')->__('Profile State'), + 'created_at' => Mage::helper('adminhtml')->__('Created At'), + 'updated_at' => Mage::helper('adminhtml')->__('Updated At'), + default => parent::getFieldLabel($field), + }; } /** @@ -437,12 +432,10 @@ public function getFieldLabel($field) */ public function getFieldComment($field) { - switch ($field) { - case 'order_item_id': - return Mage::helper('sales')->__('Original order item that recurring payment profile correspondss to.'); - default: - return parent::getFieldComment($field); - } + return match ($field) { + 'order_item_id' => Mage::helper('sales')->__('Original order item that recurring payment profile correspondss to.'), + default => parent::getFieldComment($field), + }; } /** @@ -474,22 +467,15 @@ public function getAllStates($withLabels = true) */ public function getStateLabel($state) { - switch ($state) { - case self::STATE_UNKNOWN: - return Mage::helper('sales')->__('Not Initialized'); - case self::STATE_PENDING: - return Mage::helper('sales')->__('Pending'); - case self::STATE_ACTIVE: - return Mage::helper('sales')->__('Active'); - case self::STATE_SUSPENDED: - return Mage::helper('sales')->__('Suspended'); - case self::STATE_CANCELED: - return Mage::helper('sales')->__('Canceled'); - case self::STATE_EXPIRED: - return Mage::helper('sales')->__('Expired'); - default: - return $state; - } + return match ($state) { + self::STATE_UNKNOWN => Mage::helper('sales')->__('Not Initialized'), + self::STATE_PENDING => Mage::helper('sales')->__('Pending'), + self::STATE_ACTIVE => Mage::helper('sales')->__('Active'), + self::STATE_SUSPENDED => Mage::helper('sales')->__('Suspended'), + self::STATE_CANCELED => Mage::helper('sales')->__('Canceled'), + self::STATE_EXPIRED => Mage::helper('sales')->__('Expired'), + default => $state, + }; } /** @@ -501,11 +487,10 @@ public function getStateLabel($state) public function renderData($key) { $value = $this->_getData($key); - switch ($key) { - case 'state': - return $this->getStateLabel($value); - } - return parent::renderData($key); + return match ($key) { + 'state' => $this->getStateLabel($value), + default => parent::renderData($key), + }; } /** diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Address.php b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Address.php index 0942bd1adce..5b362277692 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Address.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Address.php @@ -53,19 +53,11 @@ public function getAttributeElement() */ public function getInputType() { - switch ($this->getAttribute()) { - case 'base_subtotal': - case 'weight': - case 'total_qty': - return 'numeric'; - - case 'shipping_method': - case 'payment_method': - case 'country_id': - case 'region_id': - return 'select'; - } - return 'string'; + return match ($this->getAttribute()) { + 'base_subtotal', 'weight', 'total_qty' => 'numeric', + 'shipping_method', 'payment_method', 'country_id', 'region_id' => 'select', + default => 'string', + }; } /** @@ -73,14 +65,10 @@ public function getInputType() */ public function getValueElementType() { - switch ($this->getAttribute()) { - case 'shipping_method': - case 'payment_method': - case 'country_id': - case 'region_id': - return 'select'; - } - return 'text'; + return match ($this->getAttribute()) { + 'shipping_method', 'payment_method', 'country_id', 'region_id' => 'select', + default => 'text', + }; } /** @@ -89,30 +77,17 @@ public function getValueElementType() public function getValueSelectOptions() { if (!$this->hasData('value_select_options')) { - switch ($this->getAttribute()) { - case 'country_id': - $options = Mage::getModel('adminhtml/system_config_source_country') - ->toOptionArray(); - break; - - case 'region_id': - $options = Mage::getModel('adminhtml/system_config_source_allregion') - ->toOptionArray(); - break; - - case 'shipping_method': - $options = Mage::getModel('adminhtml/system_config_source_shipping_allmethods') - ->toOptionArray(); - break; - - case 'payment_method': - $options = Mage::getModel('adminhtml/system_config_source_payment_allmethods') - ->toOptionArray(); - break; - - default: - $options = []; - } + $options = match ($this->getAttribute()) { + 'country_id' => Mage::getModel('adminhtml/system_config_source_country') + ->toOptionArray(), + 'region_id' => Mage::getModel('adminhtml/system_config_source_allregion') + ->toOptionArray(), + 'shipping_method' => Mage::getModel('adminhtml/system_config_source_shipping_allmethods') + ->toOptionArray(), + 'payment_method' => Mage::getModel('adminhtml/system_config_source_payment_allmethods') + ->toOptionArray(), + default => [], + }; $this->setData('value_select_options', $options); } return $this->getData('value_select_options'); diff --git a/app/code/core/Mage/Uploader/Model/Config/Abstract.php b/app/code/core/Mage/Uploader/Model/Config/Abstract.php index f470150bdd9..8863da20663 100644 --- a/app/code/core/Mage/Uploader/Model/Config/Abstract.php +++ b/app/code/core/Mage/Uploader/Model/Config/Abstract.php @@ -37,19 +37,12 @@ protected function _getHelper() public function __call($method, $args) { $key = lcfirst($this->_camelize(substr($method, 3))); - switch (substr($method, 0, 3)) { - case 'get': - return $this->getData($key, $args[0] ?? null); - - case 'set': - return $this->setData($key, $args[0] ?? null); - - case 'uns': - return $this->unsetData($key); - - case 'has': - return isset($this->_data[$key]); - } - throw new Varien_Exception('Invalid method ' . get_class($this) . '::' . $method . '(' . print_r($args, true) . ')'); + return match (substr($method, 0, 3)) { + 'get' => $this->getData($key, $args[0] ?? null), + 'set' => $this->setData($key, $args[0] ?? null), + 'uns' => $this->unsetData($key), + 'has' => isset($this->_data[$key]), + default => throw new Varien_Exception('Invalid method ' . get_class($this) . '::' . $method . '(' . print_r($args, true) . ')'), + }; } } diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract.php index 3d87fbdc8b7..1700f5e849a 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract.php @@ -406,18 +406,11 @@ abstract protected function _doShipmentRequest(Varien_Object $request); */ protected function _isUSCountry($countyId) { - switch ($countyId) { - case 'AS': // Samoa American - case 'GU': // Guam - case 'MP': // Northern Mariana Islands - case 'PW': // Palau - case 'PR': // Puerto Rico - case 'VI': // Virgin Islands US - case 'US': // United States - return true; - } - - return false; + return match ($countyId) { + // United States + 'AS', 'GU', 'MP', 'PW', 'PR', 'VI', 'US' => true, + default => false, + }; } /** diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php index 92200974de2..7cab4330ad4 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php @@ -1382,31 +1382,14 @@ protected function _formUsExpressShipmentRequest(Varien_Object $request) */ protected function _formUsSignatureConfirmationShipmentRequest(Varien_Object $request, $serviceType) { - switch ($serviceType) { - case 'PRIORITY': - case 'Priority': - $serviceType = 'Priority'; - break; - case 'FIRST CLASS': - case 'First Class': - $serviceType = 'First Class'; - break; - case 'STANDARD': - case 'Standard Post': - case 'Retail Ground': - $serviceType = 'Retail Ground'; - break; - case 'MEDIA': - case 'Media': - $serviceType = 'Media Mail'; - break; - case 'LIBRARY': - case 'Library': - $serviceType = 'Library Mail'; - break; - default: - throw new Exception(Mage::helper('usa')->__('Service type does not match')); - } + $serviceType = match ($serviceType) { + 'PRIORITY', 'Priority' => 'Priority', + 'FIRST CLASS', 'First Class' => 'First Class', + 'STANDARD', 'Standard Post', 'Retail Ground' => 'Retail Ground', + 'MEDIA', 'Media' => 'Media Mail', + 'LIBRARY', 'Library' => 'Library Mail', + default => throw new Exception(Mage::helper('usa')->__('Service type does not match')), + }; $packageParams = $request->getPackageParams(); $packageWeight = $request->getPackageWeight(); if ($packageParams->getWeightUnits() != Zend_Measure_Weight::OUNCE) { @@ -1518,25 +1501,14 @@ protected function _formIntlShipmentRequest(Varien_Object $request) } $container = $request->getPackagingType(); - switch ($container) { - case 'VARIABLE': - $container = 'VARIABLE'; - break; - case 'FLAT RATE ENVELOPE': - $container = 'FLATRATEENV'; - break; - case 'FLAT RATE BOX': - $container = 'FLATRATEBOX'; - break; - case 'RECTANGULAR': - $container = 'RECTANGULAR'; - break; - case 'NONRECTANGULAR': - $container = 'NONRECTANGULAR'; - break; - default: - $container = 'VARIABLE'; - } + $container = match ($container) { + 'VARIABLE' => 'VARIABLE', + 'FLAT RATE ENVELOPE' => 'FLATRATEENV', + 'FLAT RATE BOX' => 'FLATRATEBOX', + 'RECTANGULAR' => 'RECTANGULAR', + 'NONRECTANGULAR' => 'NONRECTANGULAR', + default => 'VARIABLE', + }; $shippingMethod = $request->getShippingMethod(); [$fromZip5, $fromZip4] = $this->_parseZip($request->getShipperAddressPostalCode()); diff --git a/errors/processor.php b/errors/processor.php index ab1bc3ccafe..020d8517cb0 100644 --- a/errors/processor.php +++ b/errors/processor.php @@ -277,17 +277,11 @@ protected function _loadXml(string $xmlFile) protected function _sendHeaders(int $statusCode) { $serverProtocol = !empty($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; - switch ($statusCode) { - case 404: - $description = 'Not Found'; - break; - case 503: - $description = 'Service Unavailable'; - break; - default: - $description = ''; - break; - } + $description = match ($statusCode) { + 404 => 'Not Found', + 503 => 'Service Unavailable', + default => '', + }; header(sprintf('%s %s %s', $serverProtocol, $statusCode, $description), true, $statusCode); header(sprintf('Status: %s %s', $statusCode, $description), true, $statusCode); diff --git a/lib/Mage/Cache/Backend/File.php b/lib/Mage/Cache/Backend/File.php index a8e7b39dd8e..3b5fbb3a957 100644 --- a/lib/Mage/Cache/Backend/File.php +++ b/lib/Mage/Cache/Backend/File.php @@ -233,13 +233,10 @@ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = []) { // We use this protected method to hide the recursive stuff clearstatcache(); - switch ($mode) { - case Zend_Cache::CLEANING_MODE_ALL: - case Zend_Cache::CLEANING_MODE_OLD: - return $this->_clean($this->_options['cache_dir'], $mode); - default: - return $this->_cleanNew($mode, $tags); - } + return match ($mode) { + Zend_Cache::CLEANING_MODE_ALL, Zend_Cache::CLEANING_MODE_OLD => $this->_clean($this->_options['cache_dir'], $mode), + default => $this->_cleanNew($mode, $tags), + }; } /** diff --git a/lib/Varien/Cache/Backend/Database.php b/lib/Varien/Cache/Backend/Database.php index a70bd1857b7..864305fe311 100644 --- a/lib/Varien/Cache/Backend/Database.php +++ b/lib/Varien/Cache/Backend/Database.php @@ -547,22 +547,14 @@ protected function _cleanByTags($mode, $tags) $result = true; $select = $adapter->select() ->from($this->_getTagsTable(), 'cache_id'); - switch ($mode) { - case Zend_Cache::CLEANING_MODE_MATCHING_TAG: - $select->where('tag IN (?)', $tags) - ->group('cache_id') - ->having('COUNT(cache_id) = ' . count($tags)); - break; - case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: - $select->where('tag NOT IN (?)', $tags); - break; - case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: - $select->where('tag IN (?)', $tags); - break; - default: - Zend_Cache::throwException('Invalid mode for _cleanByTags() method'); - break; - } + match ($mode) { + Zend_Cache::CLEANING_MODE_MATCHING_TAG => $select->where('tag IN (?)', $tags) + ->group('cache_id') + ->having('COUNT(cache_id) = ' . count($tags)), + Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => $select->where('tag NOT IN (?)', $tags), + Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => $select->where('tag IN (?)', $tags), + default => Zend_Cache::throwException('Invalid mode for _cleanByTags() method'), + }; $cacheIdsToRemove = []; $counter = 0; diff --git a/lib/Varien/Db/Adapter/Pdo/Mysql.php b/lib/Varien/Db/Adapter/Pdo/Mysql.php index b1218de1291..3ea1f1813f0 100644 --- a/lib/Varien/Db/Adapter/Pdo/Mysql.php +++ b/lib/Varien/Db/Adapter/Pdo/Mysql.php @@ -2777,20 +2777,12 @@ public function addIndex( } $fieldSql = implode(',', $fieldSql); - switch (strtolower($indexType)) { - case Varien_Db_Adapter_Interface::INDEX_TYPE_PRIMARY: - $condition = 'PRIMARY KEY'; - break; - case Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE: - $condition = 'UNIQUE ' . $this->quoteIdentifier($indexName); - break; - case Varien_Db_Adapter_Interface::INDEX_TYPE_FULLTEXT: - $condition = 'FULLTEXT ' . $this->quoteIdentifier($indexName); - break; - default: - $condition = 'INDEX ' . $this->quoteIdentifier($indexName); - break; - } + $condition = match (strtolower($indexType)) { + Varien_Db_Adapter_Interface::INDEX_TYPE_PRIMARY => 'PRIMARY KEY', + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE => 'UNIQUE ' . $this->quoteIdentifier($indexName), + Varien_Db_Adapter_Interface::INDEX_TYPE_FULLTEXT => 'FULLTEXT ' . $this->quoteIdentifier($indexName), + default => 'INDEX ' . $this->quoteIdentifier($indexName), + }; $query .= sprintf(' ADD %s (%s)', $condition, $fieldSql); @@ -3919,16 +3911,12 @@ protected function _getDdlType($options) */ protected function _getDdlAction($action) { - switch ($action) { - case Varien_Db_Adapter_Interface::FK_ACTION_CASCADE: - return Varien_Db_Ddl_Table::ACTION_CASCADE; - case Varien_Db_Adapter_Interface::FK_ACTION_SET_NULL: - return Varien_Db_Ddl_Table::ACTION_SET_NULL; - case Varien_Db_Adapter_Interface::FK_ACTION_RESTRICT: - return Varien_Db_Ddl_Table::ACTION_RESTRICT; - default: - return Varien_Db_Ddl_Table::ACTION_NO_ACTION; - } + return match ($action) { + Varien_Db_Adapter_Interface::FK_ACTION_CASCADE => Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Adapter_Interface::FK_ACTION_SET_NULL => Varien_Db_Ddl_Table::ACTION_SET_NULL, + Varien_Db_Adapter_Interface::FK_ACTION_RESTRICT => Varien_Db_Ddl_Table::ACTION_RESTRICT, + default => Varien_Db_Ddl_Table::ACTION_NO_ACTION, + }; } /** diff --git a/lib/Varien/Image/Adapter.php b/lib/Varien/Image/Adapter.php index 63566f6d1bb..d1c3fd8d701 100644 --- a/lib/Varien/Image/Adapter.php +++ b/lib/Varien/Image/Adapter.php @@ -15,22 +15,11 @@ class Varien_Image_Adapter public static function factory($adapter) { - switch ($adapter) { - case self::ADAPTER_GD: - return new Varien_Image_Adapter_Gd(); - break; - - case self::ADAPTER_GD2: - return new Varien_Image_Adapter_Gd2(); - break; - - case self::ADAPTER_IM: - return new Varien_Image_Adapter_Imagemagic(); - break; - - default: - throw new Exception('Invalid adapter selected.'); - break; - } + return match ($adapter) { + self::ADAPTER_GD => new Varien_Image_Adapter_Gd(), + self::ADAPTER_GD2 => new Varien_Image_Adapter_Gd2(), + self::ADAPTER_IM => new Varien_Image_Adapter_Imagemagic(), + default => throw new Exception('Invalid adapter selected.'), + }; } } diff --git a/shell/indexer.php b/shell/indexer.php index b74e6f71384..f410dd73ed3 100644 --- a/shell/indexer.php +++ b/shell/indexer.php @@ -83,20 +83,12 @@ public function run() foreach ($processes as $process) { $status = 'unknown'; if ($this->getArg('status')) { - switch ($process->getStatus()) { - case Mage_Index_Model_Process::STATUS_PENDING: - $status = 'Pending'; - break; - case Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX: - $status = 'Require Reindex'; - break; - case Mage_Index_Model_Process::STATUS_RUNNING: - $status = 'Running'; - break; - default: - $status = 'Ready'; - break; - } + $status = match ($process->getStatus()) { + Mage_Index_Model_Process::STATUS_PENDING => 'Pending', + Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX => 'Require Reindex', + Mage_Index_Model_Process::STATUS_RUNNING => 'Running', + default => 'Ready', + }; } else { switch ($process->getMode()) { case Mage_Index_Model_Process::MODE_SCHEDULE: