11<?php
22/**
3- *
4- * Copyright © Magento, Inc. All rights reserved.
5- * See COPYING.txt for license details.
3+ * Copyright 2014 Adobe
4+ * All Rights Reserved.
65 */
76namespace Magento \Shipping \Model \Shipping ;
87
98use Magento \Framework \App \Filesystem \DirectoryList ;
109use Magento \Framework \App \RequestInterface ;
10+ use Magento \Sales \Model \Order \Shipment ;
1111
1212/**
1313 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14+ * phpcs:disable Magento2.Functions.DiscouragedFunction
1415 */
1516class LabelGenerator
1617{
@@ -61,12 +62,14 @@ public function __construct(
6162 }
6263
6364 /**
64- * @param \Magento\Sales\Model\Order\Shipment $shipment
65+ * Creates a shipping label
66+ *
67+ * @param Shipment $shipment
6568 * @param RequestInterface $request
6669 * @return void
6770 * @throws \Magento\Framework\Exception\LocalizedException
6871 */
69- public function create (\ Magento \ Sales \ Model \ Order \ Shipment $ shipment , RequestInterface $ request )
72+ public function create (Shipment $ shipment , RequestInterface $ request )
7073 {
7174 $ order = $ shipment ->getOrder ();
7275 $ carrier = $ this ->carrierFactory ->create ($ order ->getShippingMethod (true )->getCarrierCode ());
@@ -76,7 +79,8 @@ public function create(\Magento\Sales\Model\Order\Shipment $shipment, RequestInt
7679 $ shipment ->setPackages ($ request ->getParam ('packages ' ));
7780 $ response = $ this ->labelFactory ->create ()->requestToShipment ($ shipment );
7881 if ($ response ->hasErrors ()) {
79- throw new \Magento \Framework \Exception \LocalizedException (__ ($ response ->getErrors ()));
82+ $ firstError = $ response ->getErrors ()[0 ];
83+ throw new \Magento \Framework \Exception \LocalizedException (__ ($ firstError ));
8084 }
8185 if (!$ response ->hasInfo ()) {
8286 throw new \Magento \Framework \Exception \LocalizedException (__ ('Response info is not exist. ' ));
@@ -104,15 +108,17 @@ public function create(\Magento\Sales\Model\Order\Shipment $shipment, RequestInt
104108 }
105109
106110 /**
107- * @param \Magento\Sales\Model\Order\Shipment $shipment
111+ * Adds tracking number to a shipment
112+ *
113+ * @param Shipment $shipment
108114 * @param array $trackingNumbers
109115 * @param string $carrierCode
110116 * @param string $carrierTitle
111117 *
112118 * @return void
113119 */
114120 private function addTrackingNumbersToShipment (
115- \ Magento \ Sales \ Model \ Order \ Shipment $ shipment ,
121+ Shipment $ shipment ,
116122 $ trackingNumbers ,
117123 $ carrierCode ,
118124 $ carrierTitle
@@ -168,9 +174,11 @@ public function createPdfPageFromImageString($imageString)
168174 $ directory = $ this ->filesystem ->getDirectoryWrite (
169175 DirectoryList::TMP
170176 );
171- $ directory ->create ();
172- $ image = @imagecreatefromstring ($ imageString );
173- if (!$ image ) {
177+
178+ try {
179+ $ directory ->create ();
180+ $ image = imagecreatefromstring ($ imageString );
181+ } catch (\Exception $ e ) {
174182 return false ;
175183 }
176184
0 commit comments