Skip to content

Commit

Permalink
Chore: Check for DS / PS already set (#4484)
Browse files Browse the repository at this point in the history
* Check for `DS` / `PS` already set

- see phpstan/phpstan#6744

* moved duplicate code to parent class

* phpstan

---------

Co-authored-by: Ng Kiat Siong <[email protected]>
  • Loading branch information
sreichel and kiatng authored Feb 21, 2025
1 parent 2ce67cd commit cf16ac8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 89 deletions.
8 changes: 1 addition & 7 deletions .phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5200,7 +5200,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\.$#'
Expand Down Expand Up @@ -5808,12 +5808,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
Expand Down
9 changes: 5 additions & 4 deletions app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,48 @@ public function load($printQuery = false, $logQuery = false)
}
return parent::load($printQuery, $logQuery);
}


/**
* Get SQL for get record count
*
* @return Varien_Db_Select
* @see Mage_Reports_Model_Resource_Report_Product_Viewed_Collection
* @see Mage_Sales_Model_Resource_Report_Bestsellers_Collection
*/
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
* @see Mage_Reports_Model_Resource_Report_Product_Viewed_Collection
* @see Mage_Sales_Model_Resource_Report_Bestsellers_Collection
*/
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf16ac8

Please sign in to comment.