Skip to content

Commit cf16ac8

Browse files
sreichelkiatng
andauthored
Chore: Check for DS / PS already set (#4484)
* 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]>
1 parent 2ce67cd commit cf16ac8

File tree

5 files changed

+50
-89
lines changed

5 files changed

+50
-89
lines changed

.phpstan.dist.baseline.neon

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5200,7 +5200,7 @@ parameters:
52005200
message: '#^Comparison operation "\!\=" between array\|int and 0 results in an error\.$#'
52015201
identifier: notEqual.invalid
52025202
count: 1
5203-
path: app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php
5203+
path: app/code/core/Mage/Reports/Model/Resource/Report/Collection/Abstract.php
52045204

52055205
-
52065206
message: '#^Parameter \#1 \$select of method Mage_Core_Model_Resource_Helper_Mysql4\:\:getQueryUsingAnalyticFunction\(\) expects Varien_Db_Select, Zend_Db_Select given\.$#'
@@ -5808,12 +5808,6 @@ parameters:
58085808
count: 1
58095809
path: app/code/core/Mage/Sales/Model/Resource/Order/Tax/Collection.php
58105810

5811-
-
5812-
message: '#^Comparison operation "\!\=" between array\|int and 0 results in an error\.$#'
5813-
identifier: notEqual.invalid
5814-
count: 1
5815-
path: app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php
5816-
58175811
-
58185812
message: '#^Parameter \#1 \$select of method Mage_Core_Model_Resource_Helper_Mysql4\:\:getQueryUsingAnalyticFunction\(\) expects Varien_Db_Select, Zend_Db_Select given\.$#'
58195813
identifier: argument.type

app/Mage.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
1515
*/
1616

17-
define('DS', DIRECTORY_SEPARATOR);
18-
define('PS', PATH_SEPARATOR);
17+
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
18+
defined('PS') || define('PS', PATH_SEPARATOR);
19+
1920
define('BP', dirname(__DIR__));
2021

2122
Mage::register('original_include_path', get_include_path());
@@ -278,7 +279,7 @@ public static function register($key, $value, $graceful = false)
278279
if ($graceful) {
279280
return;
280281
}
281-
self::throwException('Mage registry key "' . $key . '" already exists');
282+
self::throwException("Mage registry key $key already exists");
282283
}
283284
self::$_registry[$key] = $value;
284285
}
@@ -331,7 +332,7 @@ public static function setRoot($appRoot = '')
331332
if (is_dir($appRoot) && is_readable($appRoot)) {
332333
self::$_appRoot = $appRoot;
333334
} else {
334-
self::throwException($appRoot . ' is not a directory or not readable by this user');
335+
self::throwException("$appRoot is not a directory or not readable by this user");
335336
}
336337
}
337338

app/code/core/Mage/Reports/Model/Resource/Report/Collection/Abstract.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,48 @@ public function load($printQuery = false, $logQuery = false)
268268
}
269269
return parent::load($printQuery, $logQuery);
270270
}
271+
272+
273+
/**
274+
* Get SQL for get record count
275+
*
276+
* @return Varien_Db_Select
277+
* @see Mage_Reports_Model_Resource_Report_Product_Viewed_Collection
278+
* @see Mage_Sales_Model_Resource_Report_Bestsellers_Collection
279+
*/
280+
public function getSelectCountSql()
281+
{
282+
$this->_renderFilters();
283+
$select = clone $this->getSelect();
284+
$select->reset(Zend_Db_Select::ORDER);
285+
return $this->getConnection()->select()->from($select, 'COUNT(*)');
286+
}
287+
288+
/**
289+
* Set ids for store restrictions
290+
*
291+
* @param array $storeIds
292+
* @return $this
293+
* @see Mage_Reports_Model_Resource_Report_Product_Viewed_Collection
294+
* @see Mage_Sales_Model_Resource_Report_Bestsellers_Collection
295+
*/
296+
public function addStoreRestrictions($storeIds)
297+
{
298+
if (!is_array($storeIds)) {
299+
$storeIds = [$storeIds];
300+
}
301+
$currentStoreIds = $this->_storesIds;
302+
if (isset($currentStoreIds) && $currentStoreIds != Mage_Core_Model_App::ADMIN_STORE_ID
303+
&& $currentStoreIds != [Mage_Core_Model_App::ADMIN_STORE_ID]
304+
) {
305+
if (!is_array($currentStoreIds)) {
306+
$currentStoreIds = [$currentStoreIds];
307+
}
308+
$this->_storesIds = array_intersect($currentStoreIds, $storeIds);
309+
} else {
310+
$this->_storesIds = $storeIds;
311+
}
312+
313+
return $this;
314+
}
271315
}

app/code/core/Mage/Reports/Model/Resource/Report/Product/Viewed/Collection.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -157,45 +157,6 @@ protected function _initSelect()
157157
return $this;
158158
}
159159

160-
/**
161-
* Get SQL for get record count
162-
*
163-
* @return Varien_Db_Select
164-
*/
165-
public function getSelectCountSql()
166-
{
167-
$this->_renderFilters();
168-
$select = clone $this->getSelect();
169-
$select->reset(Zend_Db_Select::ORDER);
170-
return $this->getConnection()->select()->from($select, 'COUNT(*)');
171-
}
172-
173-
/**
174-
* Set ids for store restrictions
175-
*
176-
* @param array $storeIds
177-
* @return $this
178-
*/
179-
public function addStoreRestrictions($storeIds)
180-
{
181-
if (!is_array($storeIds)) {
182-
$storeIds = [$storeIds];
183-
}
184-
$currentStoreIds = $this->_storesIds;
185-
if (isset($currentStoreIds) && $currentStoreIds != Mage_Core_Model_App::ADMIN_STORE_ID
186-
&& $currentStoreIds != [Mage_Core_Model_App::ADMIN_STORE_ID]
187-
) {
188-
if (!is_array($currentStoreIds)) {
189-
$currentStoreIds = [$currentStoreIds];
190-
}
191-
$this->_storesIds = array_intersect($currentStoreIds, $storeIds);
192-
} else {
193-
$this->_storesIds = $storeIds;
194-
}
195-
196-
return $this;
197-
}
198-
199160
/**
200161
* Redeclare parent method for applying filters after parent method
201162
* but before adding unions and calculating totals

app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -158,45 +158,6 @@ protected function _initSelect()
158158
return $this;
159159
}
160160

161-
/**
162-
* Get SQL for get record count
163-
*
164-
* @return Varien_Db_Select
165-
*/
166-
public function getSelectCountSql()
167-
{
168-
$this->_renderFilters();
169-
$select = clone $this->getSelect();
170-
$select->reset(Zend_Db_Select::ORDER);
171-
return $this->getConnection()->select()->from($select, 'COUNT(*)');
172-
}
173-
174-
/**
175-
* Set ids for store restrictions
176-
*
177-
* @param array $storeIds
178-
* @return $this
179-
*/
180-
public function addStoreRestrictions($storeIds)
181-
{
182-
if (!is_array($storeIds)) {
183-
$storeIds = [$storeIds];
184-
}
185-
$currentStoreIds = $this->_storesIds;
186-
if (isset($currentStoreIds) && $currentStoreIds != Mage_Core_Model_App::ADMIN_STORE_ID
187-
&& $currentStoreIds != [Mage_Core_Model_App::ADMIN_STORE_ID]
188-
) {
189-
if (!is_array($currentStoreIds)) {
190-
$currentStoreIds = [$currentStoreIds];
191-
}
192-
$this->_storesIds = array_intersect($currentStoreIds, $storeIds);
193-
} else {
194-
$this->_storesIds = $storeIds;
195-
}
196-
197-
return $this;
198-
}
199-
200161
/**
201162
* Redeclare parent method for applying filters after parent method
202163
* but before adding unions and calculating totals

0 commit comments

Comments
 (0)