Skip to content

Commit

Permalink
Merge branch 'main' into ref-2847-phpstan
Browse files Browse the repository at this point in the history
# Conflicts:
#	.phpstan.dist.baseline.neon
  • Loading branch information
sreichel committed Oct 14, 2024
2 parents 123aa8f + 239dbcb commit d67e024
Show file tree
Hide file tree
Showing 17 changed files with 6,485 additions and 1,675 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,20 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*

- name: Restore result cache
uses: actions/cache/restore@v3
with:
path: .phpstan.cache
key: "phpstan-result-cache-${{ github.run_id }}"
restore-keys: |
phpstan-result-cache-
- name: PHPStan Static Analysis
run: XDEBUG_MODE=off php vendor/bin/phpstan.phar analyze

- name: Save result cache
uses: actions/cache/save@v3
if: always()
with:
path: .phpstan.cache
key: "phpstan-result-cache-${{ github.run_id }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
!.phpcs*.xml.dist

# PhpStan
.phpstan.cache
.phpstan*.neon
phpstan*.neon
!.phpstan.dist.neon
Expand Down
7,691 changes: 6,053 additions & 1,638 deletions .phpstan.dist.baseline.neon

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion .phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ parameters:

# Instantiated class not found
- lib/Varien/Image/Adapter.php
level: 4
tmpDir: .phpstan.cache
level: 5
checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
treatPhpDocTypesAsCertain: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class Mage_Catalog_Block_Product_View_Type_Configurable extends Mage_Catalog_Blo
{
/**
* Prices
*
* @deprecated
* @var array
*/
protected $_prices = [];

/**
* Prepared prices
*
* @deprecated
* @var array
*/
protected $_resPrices = [];
Expand Down Expand Up @@ -216,14 +216,7 @@ public function getJsonConfig()
$optionPrices[] = $configurablePrice;
}
}
/**
* Prepare formatted values for options choose
*/
foreach ($optionPrices as $optionPrice) {
foreach ($optionPrices as $additional) {
$this->_preparePrice(abs($additional - $optionPrice));
}
}

if ($this->_validateAttributeInfo($info)) {
$attributes[$attributeId] = $info;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ protected function _getOptionDownloadUrl($route, $params)
protected function _parseExtensionsString($extensions)
{
preg_match_all('/[a-z0-9]+/si', strtolower($extensions), $matches);
if (isset($matches[0]) && is_array($matches[0]) && count($matches[0]) > 0) {
if (count($matches[0]) > 0) {
return $matches[0];
}
return null;
Expand Down
25 changes: 22 additions & 3 deletions app/code/core/Mage/Catalog/Model/Resource/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public function getLastUsedRewriteRequestIncrement($prefix, $suffix, $storeId)
$select = $adapter->select()
->from($this->getMainTable(), new Zend_Db_Expr('MAX(' . $urlIncrementPartExpression . ')'))
->where('store_id = :store_id')
// phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql
->where('request_path LIKE :request_path')
->where($adapter->prepareSqlCondition('request_path', [
'regexp' => '^' . preg_quote($prefix) . '[0-9]*' . preg_quote($suffix) . '$'
Expand Down Expand Up @@ -264,6 +265,7 @@ public function prepareRewrites($storeId, $categoryIds = null, $productIds = nul
$select->where('product_id IN(?)', $productIds);
}

// phpcs:ignore Ecg.Performance.FetchAll.Found
$rowSet = $adapter->fetchAll($select, $bind);

foreach ($rowSet as $row) {
Expand Down Expand Up @@ -467,6 +469,7 @@ protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId)
$bind['store_id'] = $storeId;
}

// phpcs:ignore Ecg.Performance.FetchAll.Found
$rowSet = $adapter->fetchAll($select, $bind);

$attributes = [];
Expand Down Expand Up @@ -608,6 +611,7 @@ public function _getProductAttribute($attributeCode, $productIds, $storeId)
$bind['store_id'] = $storeId;
}

// phpcs:ignore Ecg.Performance.FetchAll.Found
$rowSet = $adapter->fetchAll($select, $bind);

$attributes = [];
Expand Down Expand Up @@ -672,7 +676,7 @@ protected function _prepareStoreRootCategories($stores)
* Retrieve categories objects
* Either $categoryIds or $path (with ending slash) must be specified
*
* @param int|array $categoryIds
* @param int|array|null $categoryIds
* @param int $storeId
* @param string $path
* @return array
Expand Down Expand Up @@ -706,6 +710,7 @@ protected function _getCategories($categoryIds, $storeId = null, $path = null)
}

$select
// phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql
->where('main_table.path LIKE ?', $path . '%')
->order('main_table.path');
}
Expand All @@ -730,6 +735,7 @@ protected function _getCategories($categoryIds, $storeId = null, $path = null)
'store_id' => (int)$storeId
];

// phpcs:ignore Ecg.Performance.FetchAll.Found
$rowSet = $adapter->fetchAll($select, $bind);
foreach ($rowSet as $row) {
if ($storeId !== null) {
Expand Down Expand Up @@ -856,9 +862,11 @@ public function getRootChildrenIds($categoryId, $categoryPath, $includeStart = t
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from([$this->getTable('catalog/category')], ['entity_id'])
// phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql
->where('path LIKE ?', $categoryPath . '/%');

$categoryIds = [];
// phpcs:ignore Ecg.Performance.FetchAll.Found
$rowSet = $adapter->fetchAll($select);
foreach ($rowSet as $row) {
$categoryIds[$row['entity_id']] = $row['entity_id'];
Expand Down Expand Up @@ -918,7 +926,7 @@ public function getProductIdsByCategory($category)
/**
* Retrieve Product data objects
*
* @param int|array $productIds
* @param int|array|null $productIds
* @param int $storeId
* @param int $entityId
* @param int $lastEntityId
Expand Down Expand Up @@ -953,6 +961,7 @@ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId
$select->where('e.entity_id IN(?)', $productIds);
}

// phpcs:ignore Ecg.Performance.FetchAll.Found
$rowSet = $adapter->fetchAll($select, $bind);
foreach ($rowSet as $row) {
$product = new Varien_Object($row);
Expand All @@ -972,6 +981,7 @@ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId
['product_id', 'category_id']
)
->where('product_id IN(?)', array_keys($products));
// phpcs:ignore Ecg.Performance.FetchAll.Found
$categories = $adapter->fetchAll($select);
foreach ($categories as $category) {
$productId = $category['product_id'];
Expand Down Expand Up @@ -1103,13 +1113,17 @@ public function clearStoreCategoriesInvalidRewrites($storeId)
{
// Form a list of all current store categories ids
$store = $this->getStores($storeId);
if (!$store instanceof Mage_Core_Model_Store) {
return $this;
}

$rootCategoryId = $store->getRootCategoryId();
if (!$rootCategoryId) {
return $this;
}
$categoryIds = $this->getRootChildrenIds($rootCategoryId, $store->getRootCategoryPath());

// Remove all store catalog rewrites that are for some category or cartegory/product not within store categories
// Remove all store catalog rewrites that are for some category or category/product not within store categories
$where = [
'store_id = ?' => $storeId,
'category_id IS NOT NULL', // For sure check that it's a catalog rewrite
Expand All @@ -1136,6 +1150,10 @@ public function clearStoreCategoriesInvalidRewrites($storeId)
public function clearStoreProductsInvalidRewrites($storeId, $productId = null)
{
$store = $this->getStores($storeId);
if (!$store instanceof Mage_Core_Model_Store) {
return $this;
}

$adapter = $this->_getReadAdapter();
$bind = [
'website_id' => (int)$store->getWebsiteId(),
Expand Down Expand Up @@ -1269,6 +1287,7 @@ public function getRewriteByProductStore(array $products)
$select->orWhere($cond);
}

// phpcs:ignore Ecg.Performance.FetchAll.Found
$rowSet = $adapter->fetchAll($select, $bind);
foreach ($rowSet as $row) {
$result[$row['product_id']] = [
Expand Down
14 changes: 11 additions & 3 deletions app/code/core/Mage/Catalog/Model/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ public function refreshRewrites($storeId = null)
}

$this->clearStoreInvalidRewrites($storeId);
$this->refreshCategoryRewrite($this->getStores($storeId)->getRootCategoryId(), $storeId, false);
$store = $this->getStores($storeId);
if ($store instanceof Mage_Core_Model_Store) {
$this->refreshCategoryRewrite($store->getRootCategoryId(), $storeId, false);
}
$this->refreshProductRewrites($storeId);
$this->getResource()->clearCategoryProduct($storeId);

Expand Down Expand Up @@ -504,9 +507,14 @@ public function refreshProductRewrite($productId, $storeId = null)
*/
public function refreshProductRewrites($storeId)
{
$store = $this->getStores($storeId);
if (!$store instanceof Mage_Core_Model_Store) {
return $this;
}

$this->_categories = [];
$storeRootCategoryId = $this->getStores($storeId)->getRootCategoryId();
$storeRootCategoryPath = $this->getStores($storeId)->getRootCategoryPath();
$storeRootCategoryId = $store->getRootCategoryId();
$storeRootCategoryPath = $store->getRootCategoryPath();
$this->_categories[$storeRootCategoryId] = $this->getResource()->getCategory($storeRootCategoryId, $storeId);

$lastEntityId = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public function getAllowedMethods()
/**
* Get configuration data of carrier
*
* @param strin $type
* @param string $type
* @param string $code
* @return array|bool
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@
<?php if ($this->isConfigurableSwatchesEnabled()): ?>
<td style="position:relative">
<input type="hidden" disabled class="swatch-value" name="option[swatch][{{id}}]" value="{{swatch}}" />
<input type="color" class="input-color-html5 validate-hex-color-hash {{swatch_class}}" value="{{swatch}}" />
<span class="swatch-delete" data-msg-delete="<?php echo $this->escapeHtml($this->__('Are you sure to delete this fallback color?')) ?>">X</span>
<input type="color" class="input-color-html5 validate-hex-color-hash {{swatch_class}}" value="{{swatch}}" />
<button title="Delete Swatch" type="button" class="scalable delete icon-btn swatch-delete" data-msg-delete="<?php echo $this->escapeHtml($this->__('Are you sure to delete this fallback color?')) ?>">
<span><span><span>X</span></span></span>
</button>
</td>
<?php endif ?>
<?php foreach ($this->getStores() as $_store): ?>
Expand Down Expand Up @@ -114,7 +116,9 @@ var templateText =
'<td style="position:relative">'+
'<input type="hidden" disabled class="swatch-value" name="option[swatch][{{id}}]" value="{{swatch}}" />'+
'<input type="color" class="swatch-option input-color-html5 validate-hex-color-hash {{swatch_class}}" value="{{swatch}}" />'+
'<span class="swatch-delete" data-msg-delete="<?php echo Mage::helper('core')->jsQuoteEscape($this->__('Are you sure to delete this fallback color?')); ?>">X</span>'+
'<button title="Delete Swatch" type="button" class="scalable delete icon-btn swatch-delete" data-msg-delete="<?php echo Mage::helper('core')->jsQuoteEscape($this->__('Are you sure to delete this fallback color?')); ?>">'+
'<span><span><span>X</span></span></span>'+
'</button>'+
'</td>'+
<?php endif ?>
<?php foreach ($this->getStores() as $_store): ?>
Expand Down Expand Up @@ -148,6 +152,7 @@ var attributeOption = {
data.intype = optionDefaultInputType;
}
if (!data.swatch) {
data.swatch = '#ffffff';
data.swatch_class = 'swatch-disabled';
}
let newHTML = this.template.evaluate(data);
Expand Down Expand Up @@ -188,7 +193,7 @@ var attributeOption = {
}
},
swatchremove : function(event){
if (!confirm(event.target.getAttribute('data-msg-delete'))) {
if (!confirm(event.target.closest('button').getAttribute('data-msg-delete'))) {
return;
}
let element = event.target.closest('tr');
Expand Down
Loading

0 comments on commit d67e024

Please sign in to comment.