Skip to content

Commit 2220264

Browse files
authored
PhpStan: fix wrong params for uniqid (#5074)
1 parent 005b9c3 commit 2220264

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

.phpstan.dist.baseline.neon

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -684,12 +684,6 @@ parameters:
684684
count: 1
685685
path: app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php
686686

687-
-
688-
rawMessage: 'Parameter #1 $prefix of function uniqid expects string, int<0, max> given.'
689-
identifier: argument.type
690-
count: 1
691-
path: app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php
692-
693687
-
694688
rawMessage: 'Parameter #2 $callback of function array_filter expects (callable(mixed): bool)|null, Closure(array|bool|float|int|resource|string|null, int=): int given.'
695689
identifier: argument.type
@@ -2820,12 +2814,6 @@ parameters:
28202814
count: 1
28212815
path: app/code/core/Mage/Core/Model/Url/Rewrite/Request.php
28222816

2823-
-
2824-
rawMessage: 'Parameter #1 $prefix of function uniqid expects string, int<0, max> given.'
2825-
identifier: argument.type
2826-
count: 1
2827-
path: app/code/core/Mage/Core/functions.php
2828-
28292817
-
28302818
rawMessage: 'Call to an undefined method Mage_Wishlist_Model_Resource_Item_Collection::addAttributeToSelect().'
28312819
identifier: method.notFound

app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected function _getItemQtys()
2626
/**
2727
* Initialize shipment model instance
2828
*
29+
* @throws Exception
2930
* @throws Mage_Core_Exception
3031
* @return bool|Mage_Sales_Model_Order_Shipment
3132
*/
@@ -110,6 +111,8 @@ protected function _saveShipment($shipment)
110111

111112
/**
112113
* Shipment information page
114+
*
115+
* @throws Mage_Core_Exception
113116
*/
114117
public function viewAction()
115118
{
@@ -143,6 +146,8 @@ public function startAction()
143146

144147
/**
145148
* Shipment create page
149+
*
150+
* @throws Mage_Core_Exception
146151
*/
147152
public function newAction()
148153
{
@@ -165,6 +170,8 @@ public function newAction()
165170
/**
166171
* Save shipment
167172
* We can save only new shipment. Existing shipments are not editable
173+
*
174+
* @throws Mage_Core_Exception
168175
*/
169176
public function saveAction()
170177
{
@@ -216,16 +223,16 @@ public function saveAction()
216223
$this->_getSession()->addSuccess($isNeedCreateLabel ? $shipmentCreatedMessage . ' ' . $labelCreatedMessage
217224
: $shipmentCreatedMessage);
218225
Mage::getSingleton('adminhtml/session')->getCommentText(true);
219-
} catch (Mage_Core_Exception $e) {
226+
} catch (Mage_Core_Exception $mageCoreException) {
220227
if ($isNeedCreateLabel) {
221228
$responseAjax->setError(true);
222-
$responseAjax->setMessage($e->getMessage());
229+
$responseAjax->setMessage($mageCoreException->getMessage());
223230
} else {
224-
$this->_getSession()->addError($e->getMessage());
231+
$this->_getSession()->addError($mageCoreException->getMessage());
225232
$this->_redirect('*/*/new', ['order_id' => $this->getRequest()->getParam('order_id')]);
226233
}
227-
} catch (Exception $e) {
228-
Mage::logException($e);
234+
} catch (Exception $exception) {
235+
Mage::logException($exception);
229236
if ($isNeedCreateLabel) {
230237
$responseAjax->setError(true);
231238
$responseAjax->setMessage(
@@ -264,8 +271,8 @@ public function emailAction()
264271

265272
$this->_getSession()->addSuccess($this->__('The shipment has been sent.'));
266273
}
267-
} catch (Mage_Core_Exception $e) {
268-
$this->_getSession()->addError($e->getMessage());
274+
} catch (Mage_Core_Exception $mageCoreException) {
275+
$this->_getSession()->addError($mageCoreException->getMessage());
269276
} catch (Exception) {
270277
$this->_getSession()->addError($this->__('Cannot send shipment information.'));
271278
}
@@ -309,10 +316,10 @@ public function addTrackAction()
309316
'message' => $this->__('Cannot initialize shipment for adding tracking number.'),
310317
];
311318
}
312-
} catch (Mage_Core_Exception $e) {
319+
} catch (Mage_Core_Exception $mageCoreException) {
313320
$response = [
314321
'error' => true,
315-
'message' => $e->getMessage(),
322+
'message' => $mageCoreException->getMessage(),
316323
];
317324
} catch (Exception) {
318325
$response = [
@@ -438,10 +445,10 @@ public function addCommentAction()
438445

439446
$this->loadLayout(false);
440447
$response = $this->getLayout()->getBlock('shipment_comments')->toHtml();
441-
} catch (Mage_Core_Exception $e) {
448+
} catch (Mage_Core_Exception $mageCoreException) {
442449
$response = [
443450
'error' => true,
444-
'message' => $e->getMessage(),
451+
'message' => $mageCoreException->getMessage(),
445452
];
446453
$response = Mage::helper('core')->jsonEncode($response);
447454
} catch (Exception) {
@@ -503,6 +510,9 @@ protected function _needToAddDummy($item, $qtys)
503510
/**
504511
* Create shipping label for specific shipment with validation.
505512
*
513+
* @throws Mage_Core_Exception
514+
* @throws Zend_Pdf_Exception
515+
* @throws Exception
506516
* @return bool
507517
*/
508518
protected function _createShippingLabel(Mage_Sales_Model_Order_Shipment $shipment)
@@ -564,11 +574,11 @@ public function createLabelAction()
564574
$this->_getSession()->addSuccess(Mage::helper('sales')->__('The shipping label has been created.'));
565575
$response->setOk(true);
566576
}
567-
} catch (Mage_Core_Exception $e) {
577+
} catch (Mage_Core_Exception $mageCoreException) {
568578
$response->setError(true);
569-
$response->setMessage($e->getMessage());
570-
} catch (Exception $e) {
571-
Mage::logException($e);
579+
$response->setMessage($mageCoreException->getMessage());
580+
} catch (Exception $exception) {
581+
Mage::logException($exception);
572582
$response->setError(true);
573583
$response->setMessage(Mage::helper('sales')->__('An error occurred while creating shipping label.'));
574584
}
@@ -607,10 +617,10 @@ public function printLabelAction()
607617
'application/pdf',
608618
);
609619
}
610-
} catch (Mage_Core_Exception $e) {
611-
$this->_getSession()->addError($e->getMessage());
612-
} catch (Exception $e) {
613-
Mage::logException($e);
620+
} catch (Mage_Core_Exception $mageCoreException) {
621+
$this->_getSession()->addError($mageCoreException->getMessage());
622+
} catch (Exception $exception) {
623+
Mage::logException($exception);
614624
$this->_getSession()
615625
->addError(Mage::helper('sales')->__('An error occurred while creating shipping label.'));
616626
}
@@ -622,6 +632,9 @@ public function printLabelAction()
622632

623633
/**
624634
* Create pdf document with information about packages
635+
*
636+
* @throws Zend_Pdf_Exception
637+
* @throws Mage_Core_Exception
625638
*/
626639
public function printPackageAction()
627640
{
@@ -642,6 +655,8 @@ public function printPackageAction()
642655
/**
643656
* Batch print shipping labels for whole shipments.
644657
* Push pdf document with shipping labels to user browser
658+
*
659+
* @throws Zend_Pdf_Exception
645660
*/
646661
public function massPrintShippingLabelAction()
647662
{
@@ -700,6 +715,7 @@ public function massPrintShippingLabelAction()
700715
/**
701716
* Combine array of labels as instance PDF
702717
*
718+
* @throws Zend_Pdf_Exception
703719
* @return Zend_Pdf
704720
*/
705721
protected function _combineLabelsPdf(array $labelsContent)
@@ -726,6 +742,7 @@ protected function _combineLabelsPdf(array $labelsContent)
726742
* Create Zend_Pdf_Page instance with image from $imageString. Supports JPEG, PNG, GIF, WBMP, and GD2 formats.
727743
*
728744
* @param string $imageString
745+
* @throws Zend_Pdf_Exception
729746
* @return bool|Zend_Pdf_Page
730747
*/
731748
protected function _createPdfPageFromImageString($imageString)
@@ -741,7 +758,7 @@ protected function _createPdfPageFromImageString($imageString)
741758

742759
imageinterlace($image, 0);
743760
$tmpFileName = sys_get_temp_dir() . DS . 'shipping_labels_'
744-
. uniqid(mt_rand()) . time() . '.png';
761+
. uniqid((string) mt_rand()) . time() . '.png';
745762
imagepng($image, $tmpFileName);
746763
$pdfImage = Zend_Pdf_Image::imageWithPath($tmpFileName);
747764
$page->drawImage($pdfImage, 0, 0, $xSize, $ySize);
@@ -752,6 +769,7 @@ protected function _createPdfPageFromImageString($imageString)
752769
/**
753770
* Return grid with shipping items for Ajax request
754771
*
772+
* @throws Mage_Core_Exception
755773
* @return Mage_Core_Controller_Response_Http
756774
*/
757775
public function getShippingItemsGridAction()

app/code/core/Mage/Core/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ function isDirWriteable($dir)
276276
if (is_dir($dir) && is_writable($dir)) {
277277
if (stripos(PHP_OS, 'win') === 0) {
278278
$dir = ltrim($dir, DIRECTORY_SEPARATOR);
279-
$file = $dir . DIRECTORY_SEPARATOR . uniqid(mt_rand()) . '.tmp';
279+
$file = $dir . DIRECTORY_SEPARATOR . uniqid((string) mt_rand()) . '.tmp';
280280
$exist = file_exists($file);
281281
$fp = @fopen($file, 'a');
282282
if ($fp === false) {

0 commit comments

Comments
 (0)