From 68e9af23028ac79482c4ae4c52b41f27f2f3f587 Mon Sep 17 00:00:00 2001 From: thanhnd0905 Date: Thu, 21 Dec 2023 03:40:25 +0700 Subject: [PATCH] Fix error issues reported by PhpSta level2 tool in Model folder --- Api/CreateOrderInterface.php | 2 +- Api/LegacyApiInterface.php | 6 ++-- Api/OrderManagementInterface.php | 2 +- Api/ShippingInterface.php | 11 ++++++- Helper/Order.php | 3 +- Model/Api/CartManagement.php | 12 ++++---- Model/Api/CreateOrder.php | 30 +++++++++++-------- Model/Api/Data/AutomatedTesting/Address.php | 2 +- Model/Api/Data/AutomatedTesting/OrderItem.php | 2 +- Model/Api/Data/DebugInfo.php | 4 +-- Model/Api/Data/GetProductData.php | 2 +- Model/Api/Data/ProductInventoryInfo.php | 10 +++---- Model/Api/Data/ShipToStoreOption.php | 2 +- Model/Api/Data/ShippingData.php | 4 +-- Model/Api/Data/ShippingOptions.php | 4 +-- Model/Api/Data/TaxData.php | 6 ++-- Model/Api/Data/UniversalWebhookResult.php | 6 ++-- Model/Api/Debug.php | 2 +- Model/Api/DiscountCodeValidation.php | 8 +++-- Model/Api/ExtendWarrantyManagement.php | 7 +++-- Model/Api/FeatureSwitchesHook.php | 6 ++-- Model/Api/GetDefaultOrderStatuses.php | 4 +-- Model/Api/GetProduct.php | 21 ++++++++----- Model/Api/LegacyApi.php | 21 +++++++------ Model/Api/OAuthRedirect.php | 2 +- Model/Api/OrderManagement.php | 21 +++++++------ Model/Api/OrderTransactions.php | 10 +++++-- Model/Api/RouteInsuranceManagement.php | 2 +- Model/Api/ShippingMethods.php | 13 ++++---- Model/Api/ShippingTax.php | 8 +++-- Model/Api/Tax.php | 2 +- Model/Api/UniversalApi.php | 2 +- Model/Api/UniversalWebhook.php | 3 +- Model/Api/UpdateCart.php | 10 +++---- Model/Api/UpdateCartCommon.php | 7 ++--- Model/Api/UpdateCartContext.php | 4 +-- Model/Api/UpdateCartItemTrait.php | 15 +++++----- 37 files changed, 153 insertions(+), 123 deletions(-) diff --git a/Api/CreateOrderInterface.php b/Api/CreateOrderInterface.php index 5ca313d00..693cce838 100644 --- a/Api/CreateOrderInterface.php +++ b/Api/CreateOrderInterface.php @@ -33,7 +33,7 @@ interface CreateOrderInterface * @param mixed $order - which contain token and cart nodes. * @param string $currency * - * @return void + * @return mixed */ public function execute( $type = null, diff --git a/Api/LegacyApiInterface.php b/Api/LegacyApiInterface.php index ea7c5fbfa..1167793ee 100644 --- a/Api/LegacyApiInterface.php +++ b/Api/LegacyApiInterface.php @@ -36,7 +36,7 @@ interface LegacyApiInterface * @param mixed $display_id * @param mixed $source_transaction_id * @param mixed $source_transaction_reference - * @return void + * @return mixed */ public function manage( @@ -61,7 +61,7 @@ public function manage( * @param mixed $remove_items * @param mixed $discount_codes_to_add * @param mixed $discount_codes_to_remove - * @return Bolt\Boltpay\Api\Data\UpdateCartResultInterface|mixed + * @return \Bolt\Boltpay\Api\Data\UpdateCartResultInterface|mixed */ public function updateCart( $cart, @@ -123,7 +123,7 @@ public function validateDiscount(); * @param mixed $order - which contain token and cart nodes. * @param string $currency * - * @return void + * @return mixed */ public function createOrder($type = null, $order = null, $currency = null); } diff --git a/Api/OrderManagementInterface.php b/Api/OrderManagementInterface.php index 66018ec44..e1ce58a19 100644 --- a/Api/OrderManagementInterface.php +++ b/Api/OrderManagementInterface.php @@ -47,7 +47,7 @@ interface OrderManagementInterface * @param mixed $source_transaction_id * @param mixed $source_transaction_reference * - * @return void + * @return mixed */ public function manage( $id = null, diff --git a/Api/ShippingInterface.php b/Api/ShippingInterface.php index fb89b2aa9..956bbe80d 100644 --- a/Api/ShippingInterface.php +++ b/Api/ShippingInterface.php @@ -33,5 +33,14 @@ interface ShippingInterface * @param mixed $shipping_address shipping address * @return \Bolt\Boltpay\Api\Data\ShippingDataInterface */ - public function execute($cart, $shipping_address); + + /** + * @param $cart + * @param $shipping_address + * @param $shipping_option + * @param $ship_to_store_option + * @return \Bolt\Boltpay\Api\Data\ShippingDataInterface + */ + public function execute($cart, $shipping_address, $shipping_option = null, $ship_to_store_option = null); + } diff --git a/Helper/Order.php b/Helper/Order.php index b728c7a1f..bd260645c 100644 --- a/Helper/Order.php +++ b/Helper/Order.php @@ -2426,10 +2426,11 @@ private function isFullyCaptured ($order, $transaction) * @param float $amount * @param bool $notify * - * @return bool + * @return Invoice|mixed * @throws \Exception * @throws LocalizedException */ + public function createOrderInvoice($order, $amount, $notify = false, $transactionId = null) { $currencyCode = $order->getOrderCurrencyCode(); diff --git a/Model/Api/CartManagement.php b/Model/Api/CartManagement.php index 38d384a5d..60231c020 100644 --- a/Model/Api/CartManagement.php +++ b/Model/Api/CartManagement.php @@ -46,7 +46,7 @@ class CartManagement implements CartManagementInterface private $bugsnag; /** - * @var QuoteIdMaskFactory + * @var QuoteIdMaskFactory|mixed */ private $quoteIdMaskFactory; @@ -101,7 +101,7 @@ public function getMaskedId($cartId = '') if (!$maskedQuoteID) { $maskedQuoteID = $this->generateMaskQuoteId($cartId); if (!$maskedQuoteID) { - throw new WebapiException(__('Masked quote ID does not found'), 0, WebapiException::HTTP_NOT_FOUND); + throw new WebapiException(__('Masked quote ID does not found'), 0, WebapiException::HTTP_NOT_FOUND); // @phpstan-ignore-line } } @@ -112,7 +112,7 @@ public function getMaskedId($cartId = '') throw $e; } catch (Exception $e) { $this->bugsnag->notifyException($e); - throw new WebapiException(__($e->getMessage()), 0, WebapiException::HTTP_INTERNAL_ERROR); + throw new WebapiException(__($e->getMessage()), 0, WebapiException::HTTP_INTERNAL_ERROR); // @phpstan-ignore-line } } @@ -143,7 +143,7 @@ public function update($cartId = null, $isActive = null) try { $quote = $this->cartHelper->getQuoteById($cartId); if (!$quote) { - throw new WebapiException(__('Quote does not found'), 0, WebapiException::HTTP_NOT_FOUND); + throw new WebapiException(__('Quote does not found'), 0, WebapiException::HTTP_NOT_FOUND); // @phpstan-ignore-line } $quote->setIsActive((bool)$isActive)->save(); @@ -152,7 +152,7 @@ public function update($cartId = null, $isActive = null) throw $e; } catch (Exception $e) { $this->bugsnag->notifyException($e); - throw new WebapiException(__($e->getMessage()), 0, WebapiException::HTTP_INTERNAL_ERROR); + throw new WebapiException(__($e->getMessage()), 0, WebapiException::HTTP_INTERNAL_ERROR); // @phpstan-ignore-line } } @@ -178,7 +178,7 @@ public function getCartIdByMaskedId($maskedQuoteId) throw $e; } catch (Exception $e) { $this->bugsnag->notifyException($e); - throw new WebapiException(__($e->getMessage()), 0, WebapiException::HTTP_INTERNAL_ERROR); + throw new WebapiException(__($e->getMessage()), 0, WebapiException::HTTP_INTERNAL_ERROR); // @phpstan-ignore-line } } diff --git a/Model/Api/CreateOrder.php b/Model/Api/CreateOrder.php index 1001e0dbd..8552fca3f 100644 --- a/Model/Api/CreateOrder.php +++ b/Model/Api/CreateOrder.php @@ -40,6 +40,7 @@ use Magento\CatalogInventory\Helper\Data as CatalogInventoryData; use Bolt\Boltpay\Helper\Session as SessionHelper; use Bolt\Boltpay\Model\EventsForThirdPartyModules; +use Magento\Sales\Model\Order; /** * Class CreateOrder @@ -313,7 +314,7 @@ public function execute( /** * @param Quote $immutableQuote * @param \stdClass $transaction - * @return OrderModel + * @return Order * @throws \Exception * @throws BoltException */ @@ -471,7 +472,7 @@ public function validateQuoteData($quote, $transaction) /** * Validate minimum order amount * - * @param Quote $quote + * @param Quote|mixed $quote * @throws BoltException */ public function validateMinimumAmount($quote) @@ -511,7 +512,7 @@ private function arrayDiff($A, $B) } /** - * @param Quote $quote + * @param Quote|mixed $quote * @param $transaction * @throws BoltException * @throws NoSuchEntityException @@ -570,7 +571,7 @@ function ($item) { /** * Check if quote have errors. * - * @param QuoteItem $quoteItem + * @param QuoteItem|mixed $quoteItem * @return bool * @throws BoltException */ @@ -647,14 +648,17 @@ public function validateItemPrice($itemSku, $itemPrice, &$transactionItems) return true; } } - $this->bugsnag->registerCallback(function ($report) use ($itemPrice, $transactionUnitPrice) { - $report->setMetaData([ - 'Pre Auth' => [ - 'item.price' => $itemPrice, - 'transaction.unit_price' => $transactionUnitPrice, - ] - ]); - }); + if (isset($transactionUnitPrice)) { + $this->bugsnag->registerCallback(function ($report) use ($itemPrice, $transactionUnitPrice) { + $report->setMetaData([ + 'Pre Auth' => [ + 'item.price' => $itemPrice, + 'transaction.unit_price' => $transactionUnitPrice, + ] + ]); + }); + } + throw new BoltException( __('Price does not match. Item sku: ' . $itemSku), null, @@ -693,7 +697,7 @@ public function validateTax($quote, $transaction) } /** - * @param Quote $quote + * @param Quote|mixed $quote * @param \stdClass $transaction * @return void * @throws BoltException diff --git a/Model/Api/Data/AutomatedTesting/Address.php b/Model/Api/Data/AutomatedTesting/Address.php index d1ed0655e..ab3e73f7f 100644 --- a/Model/Api/Data/AutomatedTesting/Address.php +++ b/Model/Api/Data/AutomatedTesting/Address.php @@ -204,7 +204,7 @@ public function setCountry($country) } /** - * @return array|mixed + * @return array */ public function jsonSerialize(): array { diff --git a/Model/Api/Data/AutomatedTesting/OrderItem.php b/Model/Api/Data/AutomatedTesting/OrderItem.php index 5f9fbfe52..21ae59074 100644 --- a/Model/Api/Data/AutomatedTesting/OrderItem.php +++ b/Model/Api/Data/AutomatedTesting/OrderItem.php @@ -250,7 +250,7 @@ public function setTotal($total) } /** - * @return array|mixed + * @return array */ public function jsonSerialize(): array { diff --git a/Model/Api/Data/DebugInfo.php b/Model/Api/Data/DebugInfo.php index 86630069c..294a7bc21 100644 --- a/Model/Api/Data/DebugInfo.php +++ b/Model/Api/Data/DebugInfo.php @@ -132,7 +132,7 @@ public function getBoltConfigSettings() } /** - * @param \Bolt\Boltpay\Model\Api\Data\BoltConfigSetting[] + * @param \Bolt\Boltpay\Model\Api\Data\BoltConfigSetting[] $boltConfigSettings * * @return $this */ @@ -151,7 +151,7 @@ public function getOtherPluginVersions() } /** - * @param \Bolt\Boltpay\Model\Api\Data\PluginVersion[] + * @param \Bolt\Boltpay\Model\Api\Data\PluginVersion[] $otherPluginVersions * * @return $this */ diff --git a/Model/Api/Data/GetProductData.php b/Model/Api/Data/GetProductData.php index 6d5b7fd0b..a1b8de0e6 100644 --- a/Model/Api/Data/GetProductData.php +++ b/Model/Api/Data/GetProductData.php @@ -103,7 +103,7 @@ public function getParent() * Set parent info. * * @api - * @param ProductInventoryInfoInterface + * @param ProductInventoryInfoInterface $parent * * @return $this */ diff --git a/Model/Api/Data/ProductInventoryInfo.php b/Model/Api/Data/ProductInventoryInfo.php index 3fad26368..77e26b712 100644 --- a/Model/Api/Data/ProductInventoryInfo.php +++ b/Model/Api/Data/ProductInventoryInfo.php @@ -27,7 +27,7 @@ class ProductInventoryInfo implements ProductInventoryInfoInterface, \JsonSerializable { /** - * @var Bolt\Boltpay\Api\Data\ProductInterface + * @var \Bolt\Boltpay\Api\Data\ProductInterface */ private $product; @@ -41,7 +41,7 @@ class ProductInventoryInfo implements ProductInventoryInfoInterface, \JsonSerial * Get product info. * * @api - * @return Bolt\Boltpay\Api\Data\ProductInterface + * @return \Bolt\Boltpay\Api\Data\ProductInterface */ public function getProduct() { @@ -52,7 +52,7 @@ public function getProduct() * Set product info. * * @api - * @param Bolt\Boltpay\Api\Data\ProductInterface $product + * @param \Bolt\Boltpay\Api\Data\ProductInterface $product * * @return $this */ @@ -77,7 +77,7 @@ public function getStock() * Get stock info. * * @api - * @param \Magento\CatalogInventory\Api\Data\StockStatusInterface $stockItem + * @param \Magento\CatalogInventory\Api\Data\StockStatusInterface $stockStatus * @return $this */ public function setStock($stockStatus) @@ -86,8 +86,6 @@ public function setStock($stockStatus) return $this; } - - /** * @inheritDoc */ diff --git a/Model/Api/Data/ShipToStoreOption.php b/Model/Api/Data/ShipToStoreOption.php index 433b33319..e254d9b06 100644 --- a/Model/Api/Data/ShipToStoreOption.php +++ b/Model/Api/Data/ShipToStoreOption.php @@ -154,7 +154,7 @@ public function getAddress() * Set store address. * * @api - * @param \Bolt\Boltpay\Api\Data\StoreAddressInterface $storeAddress + * @param \Bolt\Boltpay\Api\Data\StoreAddressInterface $address * @return $this */ public function setAddress($address) diff --git a/Model/Api/Data/ShippingData.php b/Model/Api/Data/ShippingData.php index 1047dd208..f5c4f575e 100644 --- a/Model/Api/Data/ShippingData.php +++ b/Model/Api/Data/ShippingData.php @@ -52,7 +52,7 @@ public function getShippingOptions() * Set available shipping options. * * @api - * @param ShippingOptionInterface[] + * @param ShippingOptionInterface[] $shippingOptions * @return $this */ public function setShippingOptions($shippingOptions) @@ -76,7 +76,7 @@ public function getShipToStoreOptions() * Set available ship to store options. * * @api - * @param \Bolt\Boltpay\Api\Data\ShipToStoreOptionInterface[] + * @param \Bolt\Boltpay\Api\Data\ShipToStoreOptionInterface[] $shipToStoreOptions * @return $this */ public function setShipToStoreOptions($shipToStoreOptions) diff --git a/Model/Api/Data/ShippingOptions.php b/Model/Api/Data/ShippingOptions.php index 850eb115c..77fbcf00e 100644 --- a/Model/Api/Data/ShippingOptions.php +++ b/Model/Api/Data/ShippingOptions.php @@ -54,7 +54,7 @@ public function getShippingOptions() * Set available shipping options. * * @api - * @param ShippingOptionInterface[] + * @param ShippingOptionInterface[] $shippingOptions * * @return $this */ @@ -80,7 +80,7 @@ public function getTaxResult() * Set available shipping options. * * @api - * @param ShippingTaxInterface + * @param ShippingTaxInterface $taxResult * * @return $this */ diff --git a/Model/Api/Data/TaxData.php b/Model/Api/Data/TaxData.php index a70a61f25..78eb4f47d 100644 --- a/Model/Api/Data/TaxData.php +++ b/Model/Api/Data/TaxData.php @@ -59,7 +59,7 @@ public function getTaxResult() * Set available shipping options. * * @api - * @param TaxResultInterface + * @param TaxResultInterface $taxResult * * @return $this */ @@ -84,7 +84,7 @@ public function getShippingOption() * Set selected shipping option. * * @api - * @param ShippingOptionInterface + * @param ShippingOptionInterface $shippingOption * @return $this */ public function setShippingOption($shippingOption) @@ -108,7 +108,7 @@ public function getShipToStoreOption() * Set available ship to store option. * * @api - * @param \Bolt\Boltpay\Api\Data\ShipToStoreOptionInterface + * @param \Bolt\Boltpay\Api\Data\ShipToStoreOptionInterface $shipToStoreOption * @return $this */ public function setShipToStoreOption($shipToStoreOption) diff --git a/Model/Api/Data/UniversalWebhookResult.php b/Model/Api/Data/UniversalWebhookResult.php index 7bd54c28b..adf37354f 100644 --- a/Model/Api/Data/UniversalWebhookResult.php +++ b/Model/Api/Data/UniversalWebhookResult.php @@ -27,7 +27,7 @@ class UniversalWebhookResult implements UniversalWebhookResultInterface private $status; /** - * @var [] + * @var array */ private $error; @@ -61,7 +61,7 @@ public function setStatus($status) * Get error object * * @api - * @return [] + * @return array */ public function getError() @@ -73,7 +73,7 @@ public function getError() * Set error object * * @api - * @param [] $error + * @param array $error * @return \Bolt\Boltpay\Api\Data\UniversalWebhookResultInterface */ public function setError($error) diff --git a/Model/Api/Debug.php b/Model/Api/Debug.php index 7ad904e63..4ae0b4966 100644 --- a/Model/Api/Debug.php +++ b/Model/Api/Debug.php @@ -204,7 +204,7 @@ public function debug() * This method will handle universal api debug requests based on the type of request it is. * * @param array $data - * @return \Bolt\Boltpay\Api\Data\DebugInfo + * @return \Bolt\Boltpay\Model\Api\Data\DebugInfo * @throws BoltException * **/ public function universalDebug($data){ diff --git a/Model/Api/DiscountCodeValidation.php b/Model/Api/DiscountCodeValidation.php index 5b349540c..8b298bdf6 100644 --- a/Model/Api/DiscountCodeValidation.php +++ b/Model/Api/DiscountCodeValidation.php @@ -26,6 +26,8 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Webapi\Exception as WebApiException; use Bolt\Boltpay\Exception\BoltException; +use Magento\Quote\Model\Quote; +use Magento\SalesRule\Model\Coupon; /** * Discount Code Validation class @@ -131,7 +133,7 @@ private function handleRequest() } } else { throw new BoltException( - __('The cart.order_reference is not set or empty.'), + __('The cart.order_reference is not set or empty.'), /** @phpstan-ignore-line */ null, BoltErrorResponse::ERR_INSUFFICIENT_INFORMATION ); @@ -144,7 +146,7 @@ private function handleRequest() // Check if empty coupon was sent if ($couponCode === '') { throw new BoltException( - __('No coupon code provided'), + __('No coupon code provided'), /** @phpstan-ignore-line */ null, BoltErrorResponse::ERR_CODE_INVALID ); @@ -193,7 +195,7 @@ private function handleRequest() } elseif ($giftCard && $giftCard->getId()) { $result = $this->applyingGiftCardCode($couponCode, $giftCard, $immutableQuote, $parentQuote); } else { - throw new WebApiException(__('Something happened with current code.')); + throw new WebApiException(__('Something happened with current code.')); /** @phpstan-ignore-line */ } // we shouldn't be able to get inside this if statement. Anything resulting in it diff --git a/Model/Api/ExtendWarrantyManagement.php b/Model/Api/ExtendWarrantyManagement.php index a388791a5..d103b05b1 100644 --- a/Model/Api/ExtendWarrantyManagement.php +++ b/Model/Api/ExtendWarrantyManagement.php @@ -20,6 +20,7 @@ use Bolt\Boltpay\Api\Data\ExtendWarrantyPlanInterface; use Bolt\Boltpay\Api\ExtendWarrantyManagementInterface; use Bolt\Boltpay\Helper\Bugsnag; +use Bolt\Boltpay\Model\Api\Data\ExtendWarrantyPlan; use Magento\Framework\Webapi\Exception as WebapiException; use Magento\Framework\Webapi\Rest\Response; use Magento\Framework\Module\Manager; @@ -28,6 +29,7 @@ use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Quote\Model\Quote; /** * Extend_Warranty module management data @@ -100,11 +102,11 @@ public function __construct( * Add extend warranty product to the cart based on extend warranty data * * @param string $cartId - * @param ExtendWarrantyPlanInterface $plan + * @param ExtendWarrantyPlanInterface|mixed $plan * @return void * @throws WebapiException */ - public function addWarrantyPlan(string $cartId, ExtendWarrantyPlanInterface $plan) + public function addWarrantyPlan(string $cartId, $plan) { try { if (!$this->isModuleEnabled()) { @@ -113,6 +115,7 @@ public function addWarrantyPlan(string $cartId, ExtendWarrantyPlanInterface $pla ]; $httpResponseCode = self::RESPONSE_FAIL_STATUS; } else { + /** @var Quote $cart */ $cart = $this->cartRepository->get($cartId); $warrantyProduct = $this->getWarrantyProduct(); $orderItem = $cart->addProduct($warrantyProduct, $plan->getBuyRequest()); diff --git a/Model/Api/FeatureSwitchesHook.php b/Model/Api/FeatureSwitchesHook.php index 2662c539f..815519afb 100644 --- a/Model/Api/FeatureSwitchesHook.php +++ b/Model/Api/FeatureSwitchesHook.php @@ -70,12 +70,12 @@ class FeatureSwitchesHook implements FeatureSwitchesHookInterface /** * @param HookHelper $hookHelper - * @param OrderHelper $orderHelper + * @param StoreManagerInterface $storeManager * @param LogHelper $logHelper * @param MetricsClient $metricsClient * @param Response $response - * @param Config $configHelper - * @param Manager $fsManager, + * @param ConfigHelper $configHelper + * @param Manager $fsManager * @param BoltErrorResponse $errorResponse */ public function __construct( diff --git a/Model/Api/GetDefaultOrderStatuses.php b/Model/Api/GetDefaultOrderStatuses.php index edf7b35d5..75bc0a0ea 100644 --- a/Model/Api/GetDefaultOrderStatuses.php +++ b/Model/Api/GetDefaultOrderStatuses.php @@ -39,8 +39,8 @@ class GetDefaultOrderStatuses implements \Bolt\Boltpay\Api\GetDefaultOrderStatus private $defaultOrderStatusFactory; /** - * @param OrderConfig $orderConfig - * @param DefaultOrderStatusFactory $DefaultOrderStatusFactory + * @param OrderConfig $orderConfig + * @param DefaultOrderStatusFactory $defaultOrderStatusFactory */ public function __construct( OrderConfig $orderConfig, diff --git a/Model/Api/GetProduct.php b/Model/Api/GetProduct.php index f5298059d..017534212 100644 --- a/Model/Api/GetProduct.php +++ b/Model/Api/GetProduct.php @@ -25,9 +25,12 @@ use Exception; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Catalog\Model\Product; use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Webapi\Exception as WebapiException; +use Magento\Store\Model\Store; +use Magento\Store\Model\StoreManager; use Magento\Store\Model\StoreManagerInterface; use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface; use Magento\ConfigurableProduct\Model\Product\Type\Configurable; @@ -43,7 +46,7 @@ class GetProduct implements GetProductInterface private const BUNDLE_PRODUCT_TYPE_CODE = 'bundle'; /** - * @var GetProductDataInterface + * @var GetProductDataInterface|mixed */ private $productData; @@ -179,13 +182,16 @@ private function getProduct($productID, $sku){ } elseif ($sku != "") { $product = $this->productRepositoryInterface->get($sku, false, $this->storeID, false); } - $productInventory->setProduct($product); - $productInventory->setStock($this->getStockStatus($product)); - $this->productData->setProductInventory($productInventory); + if (isset($product)) { + $productInventory->setProduct($product); + $productInventory->setStock($this->getStockStatus($product)); + $this->productData->setProductInventory($productInventory); + } } private function getProductFamily(){ + /** @var Product|mixed $product */ $product = $this->productData->getProductInventory()->getProduct(); $configurableParent = $this->configurable->getParentIdsByChild($product->getId()); $bundleParents = ($this->bundleSelection != null) @@ -193,6 +199,7 @@ private function getProductFamily(){ : []; if (isset($configurableParent[0])){ $parentProductInventory = new ProductInventoryInfo(); + /** @var Product|mixed $parentProduct */ $parentProduct = $this->productRepositoryInterface->getById($configurableParent[0], false, $this->storeID, false); $parentProductInventory->setProduct($parentProduct); $parentProductInventory->setStock($this->getStockStatus($parentProduct)); @@ -259,7 +266,7 @@ public function execute($productID = '', $sku = '') if (!$this->featureSwitches->isProductEndpointEnabled()) { throw new WebapiException(__('The product endpoint disabled'), 0, WebapiException::HTTP_INTERNAL_ERROR); } - + /** @var Store $store */ $store = $this->storeManager->getStore(); $this->storeID = $store->getId(); $this->hookHelper->preProcessWebhook($this->storeID); @@ -286,11 +293,11 @@ public function execute($productID = '', $sku = '') /** * Collects configurable options (super attributes) available for the provided configurable product * - * @param ProductInterface $product for which to collect configurable options + * @param ProductInterface|mixed $product for which to collect configurable options * * @return void */ - protected function collectConfigurableProductOptions(ProductInterface $product) + protected function collectConfigurableProductOptions($product) { foreach ($product->getTypeInstance()->getConfigurableOptions($product) as $attribute) { $i = 0; diff --git a/Model/Api/LegacyApi.php b/Model/Api/LegacyApi.php index 2d7be92f4..5a351cb51 100644 --- a/Model/Api/LegacyApi.php +++ b/Model/Api/LegacyApi.php @@ -64,13 +64,13 @@ class LegacyApi implements LegacyApiInterface protected $updateCart; /** - * @var CreateOrderInterface $createOrder - * @var DiscountCodeValidationInterface $discountCodeValidation - * @var OrderManagementInterface $orderManagement - * @var ShippingInterface $shipping - * @var ShippingMethodsInterface $shippingMethods - * @var TaxInterface $tax - * @var UpdateCartInterface $updateCart + * @param CreateOrderInterface $createOrder + * @param DiscountCodeValidationInterface $discountCodeValidation + * @param OrderManagementInterface $orderManagement + * @param ShippingInterface $shipping + * @param ShippingMethodsInterface $shippingMethods + * @param TaxInterface $tax + * @param UpdateCartInterface $updateCart */ public function __construct( CreateOrderInterface $createOrder, @@ -100,10 +100,9 @@ public function __construct( * @param mixed $currency * @param mixed $status * @param mixed $display_id - * @param mixed $immutable_quote_id * @param mixed $source_transaction_id * @param mixed $source_transaction_reference - * @return void + * @return mixed */ public function manage( $id = null, @@ -138,7 +137,7 @@ public function manage( * @param mixed $remove_items * @param mixed $discount_codes_to_add * @param mixed $discount_codes_to_remove - * @return void + * @return \Bolt\Boltpay\Api\Data\UpdateCartResultInterface|mixed */ public function updateCart( $cart, @@ -229,7 +228,7 @@ public function validateDiscount() * @param mixed $order - which contain token and cart nodes. * @param string $currency * - * @return void + * @return mixed */ public function createOrder($type = null, $order = null, $currency = null) { diff --git a/Model/Api/OAuthRedirect.php b/Model/Api/OAuthRedirect.php index 57f7c05be..4e2968c7a 100644 --- a/Model/Api/OAuthRedirect.php +++ b/Model/Api/OAuthRedirect.php @@ -78,7 +78,7 @@ class OAuthRedirect implements OAuthRedirectInterface private $cartHelper; /** - * @var SessionHelper + * @var SessionHelper|mixed */ private $sessionHelper; diff --git a/Model/Api/OrderManagement.php b/Model/Api/OrderManagement.php index b7a5a3eb9..916357a74 100644 --- a/Model/Api/OrderManagement.php +++ b/Model/Api/OrderManagement.php @@ -177,7 +177,6 @@ public function __construct( * @param mixed $currency * @param mixed $status * @param mixed $display_id - * @param mixed $immutable_quote_id * @param mixed $source_transaction_id * @param mixed $source_transaction_reference * @@ -407,11 +406,9 @@ private function handleCartCreateApiCall($isUniversal = false) /** * Deletes a specified order by ID. - * - * @param int $id The order ID. - * @throws \Magento\Framework\Exception\CouldNotDeleteException - * @throws NoSuchEntityException - * @throws WebapiException + * @param int $id + * @return void + * @throws WebApiException */ public function deleteById($id) { @@ -439,11 +436,11 @@ public function deleteById($id) * We need this endpoing because magento API is not able to create * partial invoice without settings specific items * - * @param int $id The order ID. - * @param float $amount - * @return bool $notify - * @throws NoSuchEntityException - * @throws WebapiException + * @param $id + * @param $amount + * @param $notify + * @return int|mixed + * @throws LocalizedException */ public function createInvoice($id, $amount, $notify = false) { $order = $this->orderHelper->getOrderById($id); @@ -453,6 +450,7 @@ public function createInvoice($id, $amount, $notify = false) { } /** + * * Places an order by order ID. * We need this endpoint because we skip order place during order creation * as transaction might be failed on bolt side @@ -462,6 +460,7 @@ public function createInvoice($id, $amount, $notify = false) { * @param $transactionData * @return \Magento\Sales\Api\Data\OrderInterface * @throws CommandException + * @throws LocalizedException */ public function placeOrder($id, $transactionData) { diff --git a/Model/Api/OrderTransactions.php b/Model/Api/OrderTransactions.php index b9ec077ae..2c1be6418 100644 --- a/Model/Api/OrderTransactions.php +++ b/Model/Api/OrderTransactions.php @@ -30,7 +30,7 @@ class OrderTransactions implements OrderTransactionsInterface { /** - * @var TransactionRepositoryInterface + * @var TransactionRepositoryInterface|mixed */ private $transactionRepository; @@ -45,8 +45,14 @@ public function __construct(TransactionRepositoryInterface $transactionRepositor /** * @inheritDoc */ + + /** + * @param mixed $transaction + * @param $additionalInformation + * @return int + */ public function execute( - TransactionInterface $transaction, + $transaction, $additionalInformation ): int { $transaction->setData( diff --git a/Model/Api/RouteInsuranceManagement.php b/Model/Api/RouteInsuranceManagement.php index c878a10f1..6397d2524 100644 --- a/Model/Api/RouteInsuranceManagement.php +++ b/Model/Api/RouteInsuranceManagement.php @@ -60,7 +60,7 @@ class RouteInsuranceManagement implements \Bolt\Boltpay\Api\RouteInsuranceManage private $quoteRepository; /** - * @var CheckoutSession + * @var CheckoutSession|mixed */ private $checkoutSession; diff --git a/Model/Api/ShippingMethods.php b/Model/Api/ShippingMethods.php index 0ed0b594e..10a8ff3b3 100644 --- a/Model/Api/ShippingMethods.php +++ b/Model/Api/ShippingMethods.php @@ -154,7 +154,7 @@ class ShippingMethods implements ShippingMethodsInterface private $taxAdjusted = false; - /** @var Quote */ + /** @var Quote|mixed */ protected $quote; /** @@ -285,6 +285,7 @@ protected function checkCartItems($cart) $quoteItems['total'][$sku] += CurrencyUtils::toMinor($unitPrice * $quantity, $this->quote->getQuoteCurrencyCode()); } + $total = $this->quote->getTotals(); if (isset($total['giftwrapping']) && ($total['giftwrapping']->getGwId() || $total['giftwrapping']->getGwItemIds())) { $giftWrapping = $total['giftwrapping']; @@ -509,7 +510,7 @@ protected function throwUnknownQuoteIdException($quoteId) /** * @param $quoteId - * @return \Magento\Quote\Api\Data\CartInterface + * @return \Magento\Quote\Api\Data\CartInterface|mixed * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function getQuoteById($quoteId) @@ -531,7 +532,7 @@ protected function preprocessHook($storeId) * Fetch and apply external quote data, not stored within a quote or totals (third party modules DB tables) * If data is applied it is used as a part of the cache identifier. * - * @param Quote $quote + * @param Quote|mixed $quote * @return string */ public function applyExternalQuoteData($quote) @@ -548,7 +549,7 @@ public function applyExternalQuoteData($quote) /** * Get Shipping and Tax from cache or run the Shipping options collection routine, store it in cache and return. * - * @param Quote $quote + * @param Quote|mixed $quote * @param array $addressData * * @return ShippingOptionsInterface @@ -720,7 +721,7 @@ public function generateShippingMethodArray($quote, $shippingAddress) /** * Collects shipping options for the quote and received address data * - * @param Quote $quote + * @param Quote|mixed $quote * @param array $addressData * * @return ShippingOptionInterface[] @@ -748,7 +749,7 @@ public function getShippingOptions($quote, $addressData) } $appliedQuoteCouponCode = $quote->getCouponCode(); - + /** @var Quote\Address|mixed $shippingAddress */ $shippingAddress = $quote->getShippingAddress(); $shippingAddress->addData($addressData); $shippingAddress->setCollectShippingRates(true); diff --git a/Model/Api/ShippingTax.php b/Model/Api/ShippingTax.php index 91b554993..9b9a660b1 100644 --- a/Model/Api/ShippingTax.php +++ b/Model/Api/ShippingTax.php @@ -20,6 +20,7 @@ use Bolt\Boltpay\Api\Data\ShippingTaxDataInterface; use Bolt\Boltpay\Helper\Hook as HookHelper; use Bolt\Boltpay\Helper\Cart as CartHelper; +use Bolt\Boltpay\Model\EventsForThirdPartyModules; use Magento\Directory\Model\Region as RegionModel; use Magento\Framework\Exception\LocalizedException; use Magento\Quote\Model\Quote; @@ -108,7 +109,7 @@ abstract class ShippingTax protected $response; /** - * @var Quote + * @var Quote|mixed */ protected $quote; @@ -128,12 +129,12 @@ abstract class ShippingTax protected $shippingOptionFactory; /** - * @var ShipToStoreOptionInterfaceFactory + * @var \Bolt\Boltpay\Api\Data\ShipToStoreOptionInterfaceFactory */ protected $shipToStoreOptionFactory; /** - * @var StoreAddressInterfaceFactory + * @var \Bolt\Boltpay\Api\Data\StoreAddressInterfaceFactory|mixed */ protected $storeAddressFactory; @@ -377,6 +378,7 @@ public function handleRequest($cart = null, $shipping_address = null, $shipping_ // get the parent quote $parentQuoteId = $cart['order_reference']; + /** @var Quote|mixed $parentQuote */ $parentQuote = $this->loadQuote($parentQuoteId); $this->cartHelper->replicateQuoteData($immutableQuote, $parentQuote); diff --git a/Model/Api/Tax.php b/Model/Api/Tax.php index fed490571..923e019bd 100644 --- a/Model/Api/Tax.php +++ b/Model/Api/Tax.php @@ -201,7 +201,7 @@ public function createShippingOption($totalsInformation, $currencyCode, $shippin * @param TotalsInterface $totalsInformation * @param string $currencyCode * @param array $ship_to_store_option - * @return ShipToStoreOptionInterface + * @return \Bolt\Boltpay\Api\Data\ShipToStoreOptionInterface * @throws \Exception */ public function createInstorePickOption($totalsInformation, $currencyCode, $ship_to_store_option) diff --git a/Model/Api/UniversalApi.php b/Model/Api/UniversalApi.php index e8dff8c78..0895ed2d3 100644 --- a/Model/Api/UniversalApi.php +++ b/Model/Api/UniversalApi.php @@ -40,7 +40,7 @@ class UniversalApi implements UniversalApiInterface protected $createOrder; /** - * @var OrderManagementInterface + * @var OrderManagementInterface|mixed */ protected $orderManagement; diff --git a/Model/Api/UniversalWebhook.php b/Model/Api/UniversalWebhook.php index fcdc11f86..e9979677c 100644 --- a/Model/Api/UniversalWebhook.php +++ b/Model/Api/UniversalWebhook.php @@ -119,7 +119,8 @@ public function execute( } /** - * @param UniversalWebhookResultInterface $result + * @param $result + * @return mixed */ private function formatResponse($result) { diff --git a/Model/Api/UpdateCart.php b/Model/Api/UpdateCart.php index abcfec501..742e572a0 100644 --- a/Model/Api/UpdateCart.php +++ b/Model/Api/UpdateCart.php @@ -318,7 +318,7 @@ public function execute($cart, $add_items = null, $remove_items = null, $discoun BoltErrorResponse::ERR_SERVICE, $e->getMessage(), $e->getHttpCode(), - ($immutableQuote) ? $immutableQuote : null + isset($immutableQuote) ? $immutableQuote : null ); return false; @@ -406,7 +406,7 @@ public function discountHandler($discount_code, $cart, $customer_name = null, $c } /** - * @param Quote $quote + * @param Quote|mixed $quote * @return array * @throws \Exception */ @@ -469,10 +469,8 @@ protected function sendSuccessResponse($result, $quote = null) } /** - * @param Quote $quote - * @param array $cart - * @return UpdateCartResultInterface - * @throws \Exception + * @param $quote + * @return mixed */ public function generateResult($quote) { diff --git a/Model/Api/UpdateCartCommon.php b/Model/Api/UpdateCartCommon.php index 302f852a2..f4b1ae614 100644 --- a/Model/Api/UpdateCartCommon.php +++ b/Model/Api/UpdateCartCommon.php @@ -128,7 +128,7 @@ abstract class UpdateCartCommon protected $sessionHelper; /** - * @var ProductRepositoryInterface + * @var \Magento\Catalog\Api\ProductRepositoryInterface */ protected $productRepository; @@ -138,12 +138,12 @@ abstract class UpdateCartCommon protected $featureSwitches; /** - * @var ShippingAssignmentProcessor + * @var \Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor */ protected $shippingAssignmentProcessor; /** - * @var CartExtensionFactory + * @var \Magento\Quote\Api\Data\CartExtensionFactory */ protected $cartExtensionFactory; @@ -210,7 +210,6 @@ public function validateQuote($immutableQuoteId) ); } - /** @var Quote $parentQuote */ if ($immutableQuoteId == $parentQuoteId) { // Product Page Checkout - quotes are created as inactive $parentQuote = $this->cartHelper->getQuoteById($parentQuoteId); diff --git a/Model/Api/UpdateCartContext.php b/Model/Api/UpdateCartContext.php index cfd001d04..969e9f7cc 100644 --- a/Model/Api/UpdateCartContext.php +++ b/Model/Api/UpdateCartContext.php @@ -432,9 +432,9 @@ public function getSessionHelper() { return $this->sessionHelper; } - + /** - * @return Cache + * @return CacheInterface|mixed */ public function getCache() { diff --git a/Model/Api/UpdateCartItemTrait.php b/Model/Api/UpdateCartItemTrait.php index eca2addba..9be30493b 100644 --- a/Model/Api/UpdateCartItemTrait.php +++ b/Model/Api/UpdateCartItemTrait.php @@ -66,7 +66,7 @@ public function __construct( * @param string $productId * @param string $storeId * - * @return \Magento\Catalog\Api\Data\ProductInterface + * @return \Magento\Catalog\Api\Data\ProductInterface|mixed */ protected function getProduct($productId, $storeId) { @@ -92,15 +92,15 @@ protected function getProduct($productId, $storeId) return $product; } - + /** * Verify if the item to add is valid * - * @param Product $product - * @param array $itemToAdd - * @param string $websiteId - * - * @return boolean + * @param $product + * @param $updateItem + * @param $quoteItem + * @param $websiteId + * @return bool */ protected function verifyItemData($product, $updateItem, $quoteItem, $websiteId) { @@ -135,6 +135,7 @@ protected function verifyItemData($product, $updateItem, $quoteItem, $websiteId) // The module Magento_InventorySales has plugin to replace legacy quote item check, // so we send $qtyToCheck as $itemQty to follow its logic + /** @var mixed $checkQty */ $checkQty = $this->stockState->checkQuoteItemQty( $updateItem['product_id'], $qtyToCheck,