Skip to content

Commit

Permalink
More phpstan fixes (#4291)
Browse files Browse the repository at this point in the history
* fixes

* fixes

* updated tests

* typo

* Update app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Run.php

Co-authored-by: Ng Kiat Siong <[email protected]>

* #4291 (comment)

* revert

#4291 (comment)

* reverted comments

#4291 (comment)

* phpcs

* removed some phpcs comments

* typo

* revert

* fix

* typo

* update

* update baseline

* reverted

* Update app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php

Co-authored-by: Ng Kiat Siong <[email protected]>

* reverted some cs-comments

* cs

* reverted some cs-comments

* cs

* minor cs [skip ci]

* reverted some cs-comments [skip ci]

* minor cs [skip ci]

* minor cs [skip ci]

* minor cs [skip ci]

---------

Co-authored-by: Ng Kiat Siong <[email protected]>
  • Loading branch information
sreichel and kiatng authored Nov 12, 2024
1 parent ceebab5 commit 4a3b6fa
Show file tree
Hide file tree
Showing 73 changed files with 216 additions and 635 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
uses: actions/cache/restore@v4
with:
path: .phpstan.cache
key: "phpstan-result-cache-${{ github.run_id }}"
key: phpstan-result-cache-${{ matrix.php-versions }}-${{ github.run_id }}
restore-keys: |
phpstan-result-cache-
Expand All @@ -52,4 +52,4 @@ jobs:
if: always()
with:
path: .phpstan.cache
key: "phpstan-result-cache-${{ github.run_id }}"
key: phpstan-result-cache-${{ matrix.php-versions }}-${{ github.run_id }}
438 changes: 9 additions & 429 deletions .phpstan.dist.baseline.neon

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected function _prepareLayout()
public function getAttributes($entityType)
{
if (!isset($this->_attributes[$entityType])) {
$attributes = [];
switch ($entityType) {
case 'product':
$attributes = Mage::getSingleton('catalog/convert_parser_product')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public function getExceptions()
$liStyle = 'background-color:#FFD; ';
break;
case Varien_Convert_Exception::NOTICE:
default:
$img = 'fam_bullet_success.gif';
$liStyle = 'background-color:#DDF; ';
break;
Expand Down
11 changes: 10 additions & 1 deletion app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,10 @@ protected function _setQuoteAddress(Mage_Sales_Model_Quote_Address $address, arr
return $this;
}

/**
* @param array|Mage_Sales_Model_Quote_Address $address
* @return $this
*/
public function setShippingAddress($address)
{
if (is_array($address)) {
Expand Down Expand Up @@ -1164,6 +1168,10 @@ public function getBillingAddress()
return $this->getQuote()->getBillingAddress();
}

/**
* @param array|Mage_Sales_Model_Quote_Address $address
* @return $this
*/
public function setBillingAddress($address)
{
if (is_array($address)) {
Expand All @@ -1173,6 +1181,8 @@ public function setBillingAddress($address)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING);
$this->_setQuoteAddress($billingAddress, $address);
$billingAddress->implodeStreetAddress();
} elseif ($address instanceof Mage_Sales_Model_Quote_Address) {
$billingAddress = $address;
}

if ($this->getShippingAddress()->getSameAsBilling()) {
Expand Down Expand Up @@ -1488,7 +1498,6 @@ protected function _prepareQuoteItems()
{
foreach ($this->getQuote()->getAllItems() as $item) {
$options = [];
// phpcs:ignore Ecg.Performance.Loop.DataLoad
$productOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
if ($productOptions) {
$productOptions['info_buyRequest']['options'] = $this->_prepareOptionsForRequest($item);
Expand Down
1 change: 1 addition & 0 deletions app/code/core/Mage/Adminhtml/Model/System/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function getStoreValuesForForm($empty = false, $all = false)
if ($website->getId() != $group->getWebsiteId()) {
continue;
}
$values = [];
$groupShow = false;
foreach ($this->_storeCollection as $store) {
if ($group->getId() != $store->getGroupId()) {
Expand Down
38 changes: 24 additions & 14 deletions app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,11 @@ public function massCancelAction()
$countCancelOrder = 0;
$countNonCancelOrder = 0;
foreach ($orderIds as $orderId) {
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
$order = Mage::getModel('sales/order')->load($orderId);
if ($order->canCancel()) {
$order->cancel()
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
->save();
$countCancelOrder++;
} else {
Expand Down Expand Up @@ -375,9 +377,11 @@ public function massHoldAction()
$countHoldOrder = 0;

foreach ($orderIds as $orderId) {
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
$order = Mage::getModel('sales/order')->load($orderId);
if ($order->canHold()) {
$order->hold()
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
->save();
$countHoldOrder++;
}
Expand Down Expand Up @@ -409,9 +413,11 @@ public function massUnholdAction()
$countNonUnholdOrder = 0;

foreach ($orderIds as $orderId) {
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
$order = Mage::getModel('sales/order')->load($orderId);
if ($order->canUnhold()) {
$order->unhold()
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
->save();
$countUnholdOrder++;
} else {
Expand Down Expand Up @@ -449,18 +455,19 @@ public function massPrintAction()

/**
* Print invoices for selected orders
*
* @return Mage_Adminhtml_Sales_OrderController|void
*/
public function pdfinvoicesAction()
{
$orderIds = $this->getRequest()->getPost('order_ids');
$flag = false;
if (!empty($orderIds)) {
foreach ($orderIds as $orderId) {
$invoices = Mage::getResourceModel('sales/order_invoice_collection')
->setOrderFilter($orderId)
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
->load();
if ($invoices->getSize() > 0) {
$flag = true;
if (!isset($pdf)) {
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoices);
} else {
Expand All @@ -469,7 +476,7 @@ public function pdfinvoicesAction()
}
}
}
if ($flag) {
if (isset($pdf) && $pdf instanceof Zend_Pdf) {
return $this->_prepareDownloadResponse(
'invoice' . Mage::getSingleton('core/date')->date('Y-m-d_H-i-s') . '.pdf',
$pdf->render(),
Expand All @@ -485,18 +492,19 @@ public function pdfinvoicesAction()

/**
* Print shipments for selected orders
*
* @return Mage_Adminhtml_Sales_OrderController|void
*/
public function pdfshipmentsAction()
{
$orderIds = $this->getRequest()->getPost('order_ids');
$flag = false;
if (!empty($orderIds)) {
foreach ($orderIds as $orderId) {
$shipments = Mage::getResourceModel('sales/order_shipment_collection')
->setOrderFilter($orderId)
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
->load();
if ($shipments->getSize()) {
$flag = true;
if (!isset($pdf)) {
$pdf = Mage::getModel('sales/order_pdf_shipment')->getPdf($shipments);
} else {
Expand All @@ -505,7 +513,7 @@ public function pdfshipmentsAction()
}
}
}
if ($flag) {
if (isset($pdf) && $pdf instanceof Zend_Pdf) {
return $this->_prepareDownloadResponse(
'packingslip' . Mage::getSingleton('core/date')->date('Y-m-d_H-i-s') . '.pdf',
$pdf->render(),
Expand All @@ -521,18 +529,19 @@ public function pdfshipmentsAction()

/**
* Print creditmemos for selected orders
*
* @return Mage_Adminhtml_Sales_OrderController|void
*/
public function pdfcreditmemosAction()
{
$orderIds = $this->getRequest()->getPost('order_ids');
$flag = false;
if (!empty($orderIds)) {
foreach ($orderIds as $orderId) {
$creditmemos = Mage::getResourceModel('sales/order_creditmemo_collection')
->setOrderFilter($orderId)
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
->load();
if ($creditmemos->getSize()) {
$flag = true;
if (!isset($pdf)) {
$pdf = Mage::getModel('sales/order_pdf_creditmemo')->getPdf($creditmemos);
} else {
Expand All @@ -541,7 +550,7 @@ public function pdfcreditmemosAction()
}
}
}
if ($flag) {
if (isset($pdf) && $pdf instanceof Zend_Pdf) {
return $this->_prepareDownloadResponse(
'creditmemo' . Mage::getSingleton('core/date')->date('Y-m-d_H-i-s') . '.pdf',
$pdf->render(),
Expand All @@ -557,18 +566,19 @@ public function pdfcreditmemosAction()

/**
* Print all documents for selected orders
*
* @return Mage_Adminhtml_Sales_OrderController|void
*/
public function pdfdocsAction()
{
$orderIds = $this->getRequest()->getPost('order_ids');
$flag = false;
if (!empty($orderIds)) {
foreach ($orderIds as $orderId) {
$invoices = Mage::getResourceModel('sales/order_invoice_collection')
->setOrderFilter($orderId)
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
->load();
if ($invoices->getSize()) {
$flag = true;
if (!isset($pdf)) {
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoices);
} else {
Expand All @@ -579,9 +589,9 @@ public function pdfdocsAction()

$shipments = Mage::getResourceModel('sales/order_shipment_collection')
->setOrderFilter($orderId)
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
->load();
if ($shipments->getSize()) {
$flag = true;
if (!isset($pdf)) {
$pdf = Mage::getModel('sales/order_pdf_shipment')->getPdf($shipments);
} else {
Expand All @@ -592,9 +602,9 @@ public function pdfdocsAction()

$creditmemos = Mage::getResourceModel('sales/order_creditmemo_collection')
->setOrderFilter($orderId)
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
->load();
if ($creditmemos->getSize()) {
$flag = true;
if (!isset($pdf)) {
$pdf = Mage::getModel('sales/order_pdf_creditmemo')->getPdf($creditmemos);
} else {
Expand All @@ -603,7 +613,7 @@ public function pdfdocsAction()
}
}
}
if ($flag) {
if (isset($pdf) && $pdf instanceof Zend_Pdf) {
return $this->_prepareDownloadResponse(
'docs' . Mage::getSingleton('core/date')->date('Y-m-d_H-i-s') . '.pdf',
$pdf->render(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,30 @@ public function editStoreAction()
if (!Mage::registry('store_action')) {
Mage::register('store_action', 'edit');
}

$itemId = null;
$model = null;
$title = '';
$notExists = '';
$codeBase = '';

switch (Mage::registry('store_type')) {
case 'website':
$itemId = $this->getRequest()->getParam('website_id', null);
$itemId = $this->getRequest()->getParam('website_id');
$model = Mage::getModel('core/website');
$title = Mage::helper('core')->__('Website');
$notExists = Mage::helper('core')->__('The website does not exist.');
$codeBase = Mage::helper('core')->__('Before modifying the website code please make sure that it is not used in index.php.');
break;
case 'group':
$itemId = $this->getRequest()->getParam('group_id', null);
$itemId = $this->getRequest()->getParam('group_id');
$model = Mage::getModel('core/store_group');
$title = Mage::helper('core')->__('Store');
$notExists = Mage::helper('core')->__('The store does not exist');
$codeBase = false;
break;
case 'store':
$itemId = $this->getRequest()->getParam('store_id', null);
$itemId = $this->getRequest()->getParam('store_id');
$model = Mage::getModel('core/store');
$title = Mage::helper('core')->__('Store View');
$notExists = Mage::helper('core')->__("Store view doesn't exist");
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Api2/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class Mage_Api2_Helper_Data extends Mage_Core_Helper_Abstract
/**
* Compare order to be used in adapters list sort
*
* @param int $a
* @param int $b
* @param array $a
* @param array $b
* @return int
*/
protected static function _compareOrder($a, $b)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function getSelectionSearchUrl()
/**
* Check if used website scope price
*
* @return string
* @return bool
*/
public function isUsedWebsitePrice()
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Bundle/Model/Resource/Indexer/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected function _prepareBundlePriceByType($priceType, $entityIds = null)
$select->columns(['tax_class_id' => new Zend_Db_Expr('0')]);
} else {
$select->columns(
['tax_class_id' => $write->getCheckSql($taxClassId . ' IS NOT NULL', $taxClassId, 0)]
['tax_class_id' => $write->getCheckSql($taxClassId . ' IS NOT NULL', $taxClassId, '0')]
);
}

Expand Down
5 changes: 5 additions & 0 deletions app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public function parse()
$importIds = $batchImportModel->getIdCollection();

foreach ($importIds as $importId) {
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
$batchImportModel->load($importId);
$importData = $batchImportModel->getBatchData();

Expand Down Expand Up @@ -511,6 +512,7 @@ public function save()
// if product is new, create default values first
if (!$model->getId()) {
$new = true;
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
$model->save();

// if new product and then store is not default
Expand All @@ -520,6 +522,7 @@ public function save()
$default = Mage::getModel('catalog/product');
$default->setData($data);
$default->setStoreId(0);
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
$default->save();
unset($default);
} // end
Expand All @@ -533,6 +536,7 @@ public function save()
$storeId
);
}
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
$model->save();
}

Expand Down Expand Up @@ -564,6 +568,7 @@ public function save()
}
}
}
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
$stockItem->save();
unset($data);
unset($stockItem);
Expand Down
1 change: 0 additions & 1 deletion app/code/core/Mage/Catalog/Model/Resource/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ public function getChildrenAmount($category, $isActiveFlag = true)
'c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.entity_id = m.entity_id',
[]
)
// phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql
->where('m.path LIKE :c_path')
->where($checkSql . ' = :active_flag');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ public function addPathsFilter($paths)
$select = $this->getSelect();
$cond = [];
foreach ($paths as $path) {
// phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql
$cond[] = $this->getResource()->getReadConnection()->quoteInto('main_table.path LIKE ?', "$path%");
}
if ($cond) {
Expand Down
Loading

0 comments on commit 4a3b6fa

Please sign in to comment.