Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More phpstan fixes #4291

Merged
merged 39 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0f8b97e
fixes
sreichel Oct 18, 2024
145049a
fixes
sreichel Oct 18, 2024
b66a9f1
updated tests
sreichel Oct 18, 2024
a1d2ea7
typo
sreichel Oct 18, 2024
e500801
Merge branch 'phpstan-u' into phpstan-3
sreichel Oct 18, 2024
3555dc9
Update app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Run.php
sreichel Oct 22, 2024
b93701c
Merge branch 'main' into phpstan-3
sreichel Oct 22, 2024
7493677
https://github.com/OpenMage/magento-lts/pull/4291#discussion_r1809998064
sreichel Oct 22, 2024
4477466
revert
sreichel Oct 22, 2024
d113a0b
Merge branch 'main' into phpstan-3
sreichel Oct 23, 2024
06c4cfd
reverted comments
sreichel Oct 23, 2024
70b0820
phpcs
sreichel Oct 23, 2024
a97d3a0
removed some phpcs comments
sreichel Oct 23, 2024
1325265
typo
sreichel Oct 23, 2024
c8ec9f6
Merge branch 'main' into phpstan-3
sreichel Oct 29, 2024
83e2b96
Merge branch 'main' into phpstan-3
sreichel Oct 29, 2024
e54c053
revert
sreichel Oct 29, 2024
bf90e72
fix
sreichel Oct 29, 2024
99632ee
typo
sreichel Oct 29, 2024
2a9cd3b
update
sreichel Oct 29, 2024
360b7ec
Merge branch 'main' into phpstan-3
sreichel Oct 29, 2024
6eed28f
update baseline
sreichel Oct 29, 2024
9500529
Merge branch 'main' into phpstan-3
sreichel Oct 31, 2024
247998d
Merge branch 'main' into phpstan-3
sreichel Oct 31, 2024
124aec3
Merge branch 'main' into phpstan-3
sreichel Nov 1, 2024
b1acc1a
Merge branch 'main' into phpstan-3
sreichel Nov 5, 2024
86c8033
reverted
sreichel Nov 5, 2024
f19b235
Update app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php
sreichel Nov 8, 2024
2d32fdb
reverted some cs-comments
sreichel Nov 8, 2024
e594afb
Merge remote-tracking branch 'origin/phpstan-3' into phpstan-3
sreichel Nov 8, 2024
b399b14
cs
sreichel Nov 8, 2024
a25cef0
reverted some cs-comments
sreichel Nov 8, 2024
f7e97a1
cs
sreichel Nov 8, 2024
28f153c
minor cs [skip ci]
sreichel Nov 8, 2024
4904c7c
reverted some cs-comments [skip ci]
sreichel Nov 8, 2024
eaea9e3
minor cs [skip ci]
sreichel Nov 8, 2024
a69ae22
minor cs [skip ci]
sreichel Nov 8, 2024
ca68285
minor cs [skip ci]
sreichel Nov 8, 2024
b2ba267
Merge branch 'main' into phpstan-3
sreichel Nov 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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