Skip to content

Commit

Permalink
Fix error issues reported by PhpSta level2 tool in Observer folder
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmccombs1 committed Dec 14, 2023
1 parent 2651b32 commit 4633ac7
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Observer/Adminhtml/ActionPredispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(\Bolt\Boltpay\Model\EventsForThirdPartyModules $even
*/
public function execute(Observer $observer)
{
/** @var \Magento\Framework\App\RequestInterface $request */
/** @var \Magento\Framework\App\Request\Http $request */
$request = $observer->getData('request');
$this->eventsForThirdPartyModules->dispatchEvent(
$this->convertEventName('adminhtml_controller_action_predispatch'),
Expand Down
8 changes: 5 additions & 3 deletions Observer/Adminhtml/Sales/CreateInvoiceForRechargedOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class CreateInvoiceForRechargedOrder implements ObserverInterface
{
/**
* @var InvoiceService
* @var InvoiceService|mixed
*/
private $invoiceService;

Expand Down Expand Up @@ -58,7 +58,9 @@ public function __construct(InvoiceService $invoiceService, InvoiceSender $invoi
public function execute(Observer $observer)
{
try {
$order = $observer->getEvent()->getOrder();
/** @var mixed $event */
$event = $observer->getEvent();
$order = $event->getOrder();
$isRechargedOrder = $order->getIsRechargedOrder();
if ($isRechargedOrder && $order->canInvoice()) {
$invoice = $this->invoiceService
Expand All @@ -72,7 +74,7 @@ public function execute(Observer $observer)
}
//Add notification comment to order
$order->addStatusHistoryComment(
__('Invoice #%1 is created. Notification email is sent to customer.', $invoice->getId())
__('Invoice #%1 is created. Notification email is sent to customer.', $invoice->getId()) /** @phpstan-ignore-line */
)->setIsCustomerNotified(true);
}
return $this;
Expand Down
8 changes: 5 additions & 3 deletions Observer/Adminhtml/Sales/RechargeCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Bolt\Boltpay\Helper\Bugsnag;
use Bolt\Boltpay\Helper\Order as OrderHelper;
use Bolt\Boltpay\Model\CustomerCreditCardFactory as CustomerCreditCardFactory;
use Bolt\Boltpay\Model\Response;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
Expand Down Expand Up @@ -53,7 +54,7 @@ class RechargeCustomer implements ObserverInterface
* @param Bugsnag $bugsnag
* @param RequestInterface $request
* @param CustomerCreditCardFactory $boltCustomerCreditCardFactory
* @param Order $orderHelper
* @param OrderHelper $orderHelper
*/
public function __construct(
Bugsnag $bugsnag,
Expand All @@ -70,6 +71,7 @@ public function __construct(
public function execute(Observer $observer)
{
try {
/** @var \Magento\Framework\Event|mixed $event */
$event = $observer->getEvent();
$order = $event->getOrder();

Expand All @@ -82,16 +84,16 @@ public function execute(Observer $observer)
if ($creditCardValue = $this->request->getParam('bolt-credit-cards')) {
/** @var \Bolt\Boltpay\Model\CustomerCreditCard $boltCustomerCreditCard */
$boltCustomerCreditCard = $this->boltCustomerCreditCardFactory->create()->load($creditCardValue);
/** @var Response|mixed $response */
$response = $boltCustomerCreditCard->recharge($order);

$responseData = $response->getResponse();
$reference = $responseData->transaction->reference ?? null;
if ($reference) {
$order->addStatusHistoryComment(
__(
'Bolt recharged transaction: %1',
$this->orderHelper->formatReferenceUrl($reference)
)
) /** @phpstan-ignore-line */
);
}
$order->setData('is_recharged_order', true);
Expand Down
12 changes: 7 additions & 5 deletions Observer/OrderSaveObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Exception;
use Magento\Framework\App\CacheInterface;
use Magento\Framework\DataObjectFactory;
use Magento\Framework\Event;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

Expand All @@ -46,7 +47,7 @@ class OrderSaveObserver implements ObserverInterface
private $configHelper;

/**
* @var DataObjectFactory
* @var DataObjectFactory|mixed
*/
private $dataObjectFactory;

Expand Down Expand Up @@ -115,10 +116,11 @@ public function execute(Observer $observer)
}

$result = self::RESULT_FAILURE;
$startTime = $this->metricsClient->getCurrentTime();
try {
$startTime = $this->metricsClient->getCurrentTime();

$order = $observer->getEvent()->getOrder();
/** @var Event|mixed $event */
$event = $observer->getEvent();
$order = $event->getOrder();
$storeId = $order->getStoreId();
$currencyCode = $order->getOrderCurrencyCode();

Expand Down Expand Up @@ -150,7 +152,7 @@ public function execute(Observer $observer)

$request = $this->apiHelper->buildRequest($requestData);
$result = $this->apiHelper->sendRequest($request);
if ($result == 200) {
if ($result === 200) {
$result = self::RESULT_SUCCESS;
}
} catch (Exception $e) {
Expand Down
7 changes: 4 additions & 3 deletions Observer/PreventCustomerEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Bolt\Boltpay\Helper\FeatureSwitch\Decider;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\ActionFlag;
use Magento\Framework\App\Request\Http;
use Magento\Framework\App\Response\RedirectInterface;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
Expand Down Expand Up @@ -82,16 +83,16 @@ public function execute(Observer $observer)
return;
}

/** @var Request $request */
/** @var Http $request */
$request = $observer->getData('request');

/** @var \Magento\Framework\App\Action\AbstractAction $action */
/** @var \Magento\Framework\App\Action\AbstractAction|mixed $action */
$action = $observer->getData('controller_action');

if (in_array($request->getFullActionName(), Config::PROHIBITED_CUSTOMER_ROUTES_WITH_SSO)) {
$this->actionFlag->set('', Action::FLAG_NO_DISPATCH, true);
$this->messageManager->addErrorMessage(
__('Account editing not supported.')
__('Account editing not supported.') /** @phpstan-ignore-line */
);
$action->getResponse()->setRedirect($this->redirect->error($this->urlManager->getUrl('customer/account')));
}
Expand Down
5 changes: 4 additions & 1 deletion Observer/PublishBoltProductEventObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Bolt\Boltpay\Observer;

use Bolt\Boltpay\Model\CatalogIngestion\ProductEventProcessor;
use Magento\Framework\Event;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;
use Magento\Catalog\Model\Product;
Expand Down Expand Up @@ -51,8 +52,10 @@ public function __construct(
*/
public function execute(Observer $observer)
{
/** @var Event|mixed $event */
$event = $observer->getEvent();
/** @var Product $product */
$product = $observer->getEvent()->getProduct();
$product = $event->getProduct();
$this->productEventProcessor->processProductEventUpdateByProduct($product);
}
}
2 changes: 1 addition & 1 deletion Observer/RemoveBlocksObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function __construct(
public function execute(Observer $observer)
{
$fullActionName = $observer->getData('full_action_name');
$layout = $observer->getLayout();
$layout = $observer->getData('layout');
$BoltSSOPages = [ConfigHelper::LOGIN_PAGE_ACTION, ConfigHelper::CREATE_ACCOUNT_PAGE_ACTION];
$showParam = $this->request->getParam(self::URL_SHOW_PARAM);
if (in_array($fullActionName, $BoltSSOPages)) {
Expand Down
13 changes: 9 additions & 4 deletions Observer/TrackingSaveObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
use Exception;
use Magento\Catalog\Model\ProductRepository;
use Magento\Framework\DataObjectFactory;
use Magento\Framework\Event;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Sales\Model\Order;
use Magento\Shipping\Model\Order\Track;

class TrackingSaveObserver implements ObserverInterface
{
Expand All @@ -38,7 +41,7 @@ class TrackingSaveObserver implements ObserverInterface
private $configHelper;

/**
* @var DataObjectFactory
* @var DataObjectFactory|mixed
*/
private $dataObjectFactory;

Expand Down Expand Up @@ -101,8 +104,10 @@ public function execute(Observer $observer)
}
$startTime = $this->metricsClient->getCurrentTime();
try {
/** @var Event|mixed $event */
$event = $observer->getEvent();
/** @var \Magento\Sales\Model\Order\Shipment\Track $tracking */
$tracking = $observer->getEvent()->getTrack();
$tracking = $event->getTrack();

// If we update track (don't create) and carrier and number are the same do nothing
if (!$this->isTrackNew($tracking)) {
Expand All @@ -117,6 +122,7 @@ public function execute(Observer $observer)

/** @var \Magento\Sales\Model\Order\Shipment $shipment */
$shipment = $tracking->getShipment();
/** @var Order|mixed $order */
$order = $shipment->getOrder();
$payment = $order->getPayment();

Expand Down Expand Up @@ -208,7 +214,7 @@ public function execute(Observer $observer)
$request = $this->apiHelper->buildRequest($requestData);
$result = $this->apiHelper->sendRequest($request);

if ($result != 200) {
if ($result !== 200) {
$this->metricsClient->processMetric(
'tracking_creation.failure',
1,
Expand Down Expand Up @@ -259,7 +265,6 @@ private function isTrackNew($track)
/**
* Convert item options into bolt format
*
* @param array item options
* @param mixed $itemOptions
*
* @return array
Expand Down

0 comments on commit 4633ac7

Please sign in to comment.