From 08e4ed269fe6e58c3c4eb85cd4c1d6c56f19360d Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Wed, 15 Jan 2025 05:23:17 +0100 Subject: [PATCH 1/3] Check for `DS` / `PS` already set - see https://github.com/phpstan/phpstan/issues/6744 --- app/Mage.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Mage.php b/app/Mage.php index ec7df4782f2..5bb2bba46f0 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -14,8 +14,9 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -define('DS', DIRECTORY_SEPARATOR); -define('PS', PATH_SEPARATOR); +defined('DS') || define('DS', DIRECTORY_SEPARATOR); +defined('PS') || define('PS', PATH_SEPARATOR); + define('BP', dirname(__DIR__)); Mage::register('original_include_path', get_include_path()); @@ -278,7 +279,7 @@ public static function register($key, $value, $graceful = false) if ($graceful) { return; } - self::throwException('Mage registry key "' . $key . '" already exists'); + self::throwException("Mage registry key $key already exists"); } self::$_registry[$key] = $value; } @@ -331,7 +332,7 @@ public static function setRoot($appRoot = '') if (is_dir($appRoot) && is_readable($appRoot)) { self::$_appRoot = $appRoot; } else { - self::throwException($appRoot . ' is not a directory or not readable by this user'); + self::throwException("$appRoot is not a directory or not readable by this user"); } } From cb3fbbac519c1ba186db138556cf9367cd28bf71 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Wed, 15 Jan 2025 05:39:56 +0100 Subject: [PATCH 2/3] moved duplicate code to parent class --- .../Resource/Report/Collection/Abstract.php | 40 +++++++++++++++++++ .../Report/Product/Viewed/Collection.php | 39 ------------------ .../Report/Bestsellers/Collection.php | 39 ------------------ 3 files changed, 40 insertions(+), 78 deletions(-) diff --git a/app/code/core/Mage/Reports/Model/Resource/Report/Collection/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Report/Collection/Abstract.php index b502f0a6e38..9ccbf138622 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Report/Collection/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Resource/Report/Collection/Abstract.php @@ -268,4 +268,44 @@ public function load($printQuery = false, $logQuery = false) } return parent::load($printQuery, $logQuery); } + + + /** + * Get SQL for get record count + * + * @return Varien_Db_Select + */ + public function getSelectCountSql() + { + $this->_renderFilters(); + $select = clone $this->getSelect(); + $select->reset(Zend_Db_Select::ORDER); + return $this->getConnection()->select()->from($select, 'COUNT(*)'); + } + + /** + * Set ids for store restrictions + * + * @param array $storeIds + * @return $this + */ + public function addStoreRestrictions($storeIds) + { + if (!is_array($storeIds)) { + $storeIds = [$storeIds]; + } + $currentStoreIds = $this->_storesIds; + if (isset($currentStoreIds) && $currentStoreIds != Mage_Core_Model_App::ADMIN_STORE_ID + && $currentStoreIds != [Mage_Core_Model_App::ADMIN_STORE_ID] + ) { + if (!is_array($currentStoreIds)) { + $currentStoreIds = [$currentStoreIds]; + } + $this->_storesIds = array_intersect($currentStoreIds, $storeIds); + } else { + $this->_storesIds = $storeIds; + } + + return $this; + } } diff --git a/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php index dbe8d77391d..30ae025b2be 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php +++ b/app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php @@ -157,45 +157,6 @@ protected function _initSelect() return $this; } - /** - * Get SQL for get record count - * - * @return Varien_Db_Select - */ - public function getSelectCountSql() - { - $this->_renderFilters(); - $select = clone $this->getSelect(); - $select->reset(Zend_Db_Select::ORDER); - return $this->getConnection()->select()->from($select, 'COUNT(*)'); - } - - /** - * Set ids for store restrictions - * - * @param array $storeIds - * @return $this - */ - public function addStoreRestrictions($storeIds) - { - if (!is_array($storeIds)) { - $storeIds = [$storeIds]; - } - $currentStoreIds = $this->_storesIds; - if (isset($currentStoreIds) && $currentStoreIds != Mage_Core_Model_App::ADMIN_STORE_ID - && $currentStoreIds != [Mage_Core_Model_App::ADMIN_STORE_ID] - ) { - if (!is_array($currentStoreIds)) { - $currentStoreIds = [$currentStoreIds]; - } - $this->_storesIds = array_intersect($currentStoreIds, $storeIds); - } else { - $this->_storesIds = $storeIds; - } - - return $this; - } - /** * Redeclare parent method for applying filters after parent method * but before adding unions and calculating totals diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php index f2bd3a13db3..40bbec8a379 100644 --- a/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php @@ -158,45 +158,6 @@ protected function _initSelect() return $this; } - /** - * Get SQL for get record count - * - * @return Varien_Db_Select - */ - public function getSelectCountSql() - { - $this->_renderFilters(); - $select = clone $this->getSelect(); - $select->reset(Zend_Db_Select::ORDER); - return $this->getConnection()->select()->from($select, 'COUNT(*)'); - } - - /** - * Set ids for store restrictions - * - * @param array $storeIds - * @return $this - */ - public function addStoreRestrictions($storeIds) - { - if (!is_array($storeIds)) { - $storeIds = [$storeIds]; - } - $currentStoreIds = $this->_storesIds; - if (isset($currentStoreIds) && $currentStoreIds != Mage_Core_Model_App::ADMIN_STORE_ID - && $currentStoreIds != [Mage_Core_Model_App::ADMIN_STORE_ID] - ) { - if (!is_array($currentStoreIds)) { - $currentStoreIds = [$currentStoreIds]; - } - $this->_storesIds = array_intersect($currentStoreIds, $storeIds); - } else { - $this->_storesIds = $storeIds; - } - - return $this; - } - /** * Redeclare parent method for applying filters after parent method * but before adding unions and calculating totals From bb51bb4c8af07de929aeb7ae8bff8a0ddaf65f4c Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Wed, 15 Jan 2025 06:04:17 +0100 Subject: [PATCH 3/3] phpstan --- .phpstan.dist.baseline.neon | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.phpstan.dist.baseline.neon b/.phpstan.dist.baseline.neon index f9f7f2e4abb..dfd0ed8db58 100644 --- a/.phpstan.dist.baseline.neon +++ b/.phpstan.dist.baseline.neon @@ -5218,7 +5218,7 @@ parameters: message: '#^Comparison operation "\!\=" between array\|int and 0 results in an error\.$#' identifier: notEqual.invalid count: 1 - path: app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php + path: app/code/core/Mage/Reports/Model/Resource/Report/Collection/Abstract.php - message: '#^Parameter \#1 \$select of method Mage_Core_Model_Resource_Helper_Mysql4\:\:getQueryUsingAnalyticFunction\(\) expects Varien_Db_Select, Zend_Db_Select given\.$#' @@ -5826,12 +5826,6 @@ parameters: count: 1 path: app/code/core/Mage/Sales/Model/Resource/Order/Tax/Collection.php - - - message: '#^Comparison operation "\!\=" between array\|int and 0 results in an error\.$#' - identifier: notEqual.invalid - count: 1 - path: app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php - - message: '#^Parameter \#1 \$select of method Mage_Core_Model_Resource_Helper_Mysql4\:\:getQueryUsingAnalyticFunction\(\) expects Varien_Db_Select, Zend_Db_Select given\.$#' identifier: argument.type