Skip to content

Commit 38c333f

Browse files
committed
MAGE-941 Fix types
1 parent 421f613 commit 38c333f

File tree

1 file changed

+48
-32
lines changed

1 file changed

+48
-32
lines changed

Block/Algolia.php

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,31 @@
1111
use Algolia\AlgoliaSearch\Helper\Entity\SuggestionHelper;
1212
use Algolia\AlgoliaSearch\Helper\LandingPageHelper;
1313
use Algolia\AlgoliaSearch\Registry\CurrentCategory;
14+
use Algolia\AlgoliaSearch\Registry\CurrentProduct;
1415
use Algolia\AlgoliaSearch\Service\Product\SortingTransformer;
15-
use Magento\Catalog\Model\Product;
16+
use Magento\Catalog\Api\Data\CategoryInterface;
17+
use Magento\Catalog\Api\Data\ProductInterface;
1618
use Magento\Checkout\Model\Session as CheckoutSession;
1719
use Magento\Customer\Model\Context as CustomerContext;
1820
use Magento\Framework\App\ActionInterface;
1921
use Magento\Framework\App\Http\Context as HttpContext;
22+
use Magento\Framework\Currency\Exception\CurrencyException;
2023
use Magento\Framework\Data\CollectionDataSourceInterface;
2124
use Magento\Framework\Data\Form\FormKey;
25+
use Magento\Framework\Exception\LocalizedException;
26+
use Magento\Framework\Exception\NoSuchEntityException;
2227
use Magento\Framework\Locale\Currency;
2328
use Magento\Framework\Locale\Format;
24-
use Algolia\AlgoliaSearch\Registry\CurrentProduct;
2529
use Magento\Framework\Stdlib\DateTime\DateTime;
2630
use Magento\Framework\Url\Helper\Data as UrlHelper;
2731
use Magento\Framework\View\Element\Template;
28-
use Magento\Framework\View\Element\Template\Context;
2932
use Magento\Sales\Model\Order;
3033
use Magento\Search\Helper\Data as CatalogSearchHelper;
34+
use Magento\Store\Api\Data\StoreInterface;
3135

3236
class Algolia extends Template implements CollectionDataSourceInterface
3337
{
34-
protected $priceKey;
38+
protected ?string $priceKey = null;
3539

3640
public function __construct(
3741
protected ConfigHelper $config,
@@ -61,66 +65,70 @@ public function __construct(
6165
}
6266

6367
/**
64-
* @return \Magento\Store\Model\Store
68+
* @throws NoSuchEntityException
6569
*/
66-
public function getStore()
70+
public function getStore(): StoreInterface
6771
{
68-
/** @var \Magento\Store\Model\Store $store */
69-
$store = $this->_storeManager->getStore();
70-
71-
return $store;
72+
return $this->_storeManager->getStore();
7273
}
7374

74-
public function getConfigHelper()
75+
public function getConfigHelper(): ConfigHelper
7576
{
7677
return $this->config;
7778
}
7879

79-
public function getCoreHelper()
80+
public function getCoreHelper(): CoreHelper
8081
{
8182
return $this->coreHelper;
8283
}
8384

84-
public function getProductHelper()
85+
public function getProductHelper(): ProductHelper
8586
{
8687
return $this->productHelper;
8788
}
8889

89-
public function getCategoryHelper()
90+
public function getCategoryHelper(): CategoryHelper
9091
{
9192
return $this->categoryHelper;
9293
}
9394

94-
public function getSuggestionHelper()
95+
public function getSuggestionHelper(): SuggestionHelper
9596
{
9697
return $this->suggestionHelper;
9798
}
9899

99-
public function getCatalogSearchHelper()
100+
public function getCatalogSearchHelper(): CatalogSearchHelper
100101
{
101102
return $this->catalogSearchHelper;
102103
}
103104

104-
public function getAlgoliaHelper()
105+
public function getAlgoliaHelper(): AlgoliaHelper
105106
{
106107
return $this->algoliaHelper;
107108
}
108109

109-
public function getPersonalizationHelper()
110+
public function getPersonalizationHelper(): PersonalizationHelper
110111
{
111112
return $this->personalizationHelper;
112113
}
113114

114-
public function getCurrencySymbol()
115+
/**
116+
* @throws CurrencyException|NoSuchEntityException
117+
*/
118+
public function getCurrencySymbol(): ?string
115119
{
116120
return $this->currency->getCurrency($this->getCurrencyCode())->getSymbol();
117121
}
118-
public function getCurrencyCode()
122+
123+
/**
124+
* @throws NoSuchEntityException
125+
*/
126+
public function getCurrencyCode(): ?string
119127
{
120128
return $this->getStore()->getCurrentCurrencyCode();
121129
}
122130

123-
public function getPriceFormat()
131+
public function getPriceFormat(): array
124132
{
125133
return $this->format->getPriceFormat();
126134
}
@@ -130,7 +138,10 @@ public function getGroupId()
130138
return $this->httpContext->getValue(CustomerContext::CONTEXT_GROUP);
131139
}
132140

133-
public function getPriceKey()
141+
/**
142+
* @throws NoSuchEntityException
143+
*/
144+
public function getPriceKey(): string
134145
{
135146
if ($this->priceKey === null) {
136147
$currencyCode = $this->getCurrencyCode();
@@ -146,29 +157,34 @@ public function getPriceKey()
146157
return $this->priceKey;
147158
}
148159

149-
public function getStoreId()
160+
/**
161+
* @throws NoSuchEntityException
162+
*/
163+
public function getStoreId(): int
150164
{
151165
return $this->getStore()->getStoreId();
152166
}
153167

154-
public function getCurrentCategory()
168+
public function getCurrentCategory(): CategoryInterface
155169
{
156170
return $this->currentCategory->get();
157171
}
158172

159-
/** @return Product */
160-
public function getCurrentProduct()
173+
public function getCurrentProduct(): ProductInterface
161174
{
162175
return $this->currentProduct->get();
163176
}
164177

165-
/** @return Order */
166-
public function getLastOrder()
178+
public function getLastOrder(): Order
167179
{
168180
return $this->checkoutSession->getLastRealOrder();
169181
}
170182

171-
public function getAddToCartParams() : array
183+
/**
184+
* @return array<string, string>
185+
* @throws LocalizedException
186+
*/
187+
public function getAddToCartParams(): array
172188
{
173189
return [
174190
'action' => $this->_urlBuilder->getUrl('checkout/cart/add', []),
@@ -177,15 +193,15 @@ public function getAddToCartParams() : array
177193
];
178194
}
179195

180-
public function getTimestamp()
196+
public function getTimestamp(): int|false
181197
{
182198
return $this->date->gmtTimestamp('today midnight');
183199
}
184200

185201
/**
186202
* @deprecated This function is deprecated as redirect routes must be derived on the frontend not backend
187203
*/
188-
protected function getAddToCartUrl($additional = [])
204+
protected function getAddToCartUrl($additional = []): string
189205
{
190206
$continueUrl = $this->urlHelper->getEncodedUrl($this->_urlBuilder->getCurrentUrl());
191207
$urlParamName = ActionInterface::PARAM_NAME_URL_ENCODED;
@@ -199,7 +215,7 @@ protected function getAddToCartUrl($additional = [])
199215
return $this->_urlBuilder->getUrl('checkout/cart/add', $routeParams);
200216
}
201217

202-
protected function getCurrentLandingPage()
218+
protected function getCurrentLandingPage(): LandingPage|null|false
203219
{
204220
$landingPageId = $this->getRequest()->getParam('landing_page_id');
205221
if (!$landingPageId) {

0 commit comments

Comments
 (0)