Skip to content

Commit b4c48a7

Browse files
committed
Fix type hints and replace deprecated method usage
1 parent 062662d commit b4c48a7

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

app/code/Magento/Newsletter/Controller/Subscriber/Confirm.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Confirm extends \Magento\Newsletter\Controller\Subscriber
1010
{
1111
/**
1212
* Subscription confirm action
13-
* @return void
13+
* @return \Magento\Framework\Controller\Result\Redirect
1414
*/
1515
public function execute()
1616
{
@@ -23,17 +23,17 @@ public function execute()
2323

2424
if ($subscriber->getId() && $subscriber->getCode()) {
2525
if ($subscriber->confirm($code)) {
26-
$this->messageManager->addSuccess(__('Your subscription has been confirmed.'));
26+
$this->messageManager->addSuccessMessage(__('Your subscription has been confirmed.'));
2727
} else {
28-
$this->messageManager->addError(__('This is an invalid subscription confirmation code.'));
28+
$this->messageManager->addErrorMessage(__('This is an invalid subscription confirmation code.'));
2929
}
3030
} else {
31-
$this->messageManager->addError(__('This is an invalid subscription ID.'));
31+
$this->messageManager->addErrorMessage(__('This is an invalid subscription ID.'));
3232
}
3333
}
34-
35-
$resultRedirect = $this->resultRedirectFactory->create();
36-
$resultRedirect->setUrl($this->_storeManager->getStore()->getBaseUrl());
37-
return $resultRedirect;
34+
/** @var \Magento\Framework\Controller\Result\Redirect $redirect */
35+
$redirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
36+
$redirectUrl = $this->_storeManager->getStore()->getBaseUrl();
37+
return $redirect->setUrl($redirectUrl);
3838
}
3939
}

app/code/Magento/Newsletter/Controller/Subscriber/NewAction.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected function validateEmailFormat($email)
131131
/**
132132
* New subscription action
133133
*
134-
* @return void
134+
* @return \Magento\Framework\Controller\Result\Redirect
135135
*/
136136
public function execute()
137137
{
@@ -160,7 +160,10 @@ public function execute()
160160
$this->messageManager->addExceptionMessage($e, __('Something went wrong with the subscription.'));
161161
}
162162
}
163-
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
163+
/** @var \Magento\Framework\Controller\Result\Redirect $redirect */
164+
$redirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
165+
$redirectUrl = $this->_redirect->getRedirectUrl();
166+
return $redirect->setUrl($redirectUrl);
164167
}
165168

166169
/**

app/code/Magento/Newsletter/Controller/Subscriber/Unsubscribe.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Unsubscribe extends \Magento\Newsletter\Controller\Subscriber implements H
1515
/**
1616
* Unsubscribe newsletter.
1717
*
18-
* @return \Magento\Backend\Model\View\Result\Redirect
18+
* @return \Magento\Framework\Controller\Result\Redirect
1919
*/
2020
public function execute()
2121
{
@@ -25,14 +25,14 @@ public function execute()
2525
if ($id && $code) {
2626
try {
2727
$this->_subscriberFactory->create()->load($id)->setCheckCode($code)->unsubscribe();
28-
$this->messageManager->addSuccess(__('You unsubscribed.'));
28+
$this->messageManager->addSuccessMessage(__('You unsubscribed.'));
2929
} catch (\Magento\Framework\Exception\LocalizedException $e) {
30-
$this->messageManager->addException($e, $e->getMessage());
30+
$this->messageManager->addErrorMessage($e, $e->getMessage());
3131
} catch (\Exception $e) {
32-
$this->messageManager->addException($e, __('Something went wrong while unsubscribing you.'));
32+
$this->messageManager->addErrorMessage($e, __('Something went wrong while unsubscribing you.'));
3333
}
3434
}
35-
/** @var \Magento\Backend\Model\View\Result\Redirect $redirect */
35+
/** @var \Magento\Framework\Controller\Result\Redirect $redirect */
3636
$redirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
3737
$redirectUrl = $this->_redirect->getRedirectUrl();
3838
return $redirect->setUrl($redirectUrl);

0 commit comments

Comments
 (0)