Skip to content

Commit 00bdd11

Browse files
committed
Address Static Test feedback
1 parent 64dd896 commit 00bdd11

File tree

3 files changed

+94
-104
lines changed

3 files changed

+94
-104
lines changed

app/code/Meta/BusinessExtension/Helper/MagentoDataHelper.php

Lines changed: 36 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
namespace Meta\BusinessExtension\Helper;
1919

20+
use Magento\Catalog\Api\Data\ProductInterface;
2021
use Magento\Catalog\Api\ProductRepositoryInterface;
2122
use Magento\Customer\Api\CustomerMetadataInterface;
23+
use Magento\Framework\Exception\LocalizedException;
2224
use Magento\Store\Model\StoreManagerInterface;
2325
use Magento\Checkout\Model\Session as CheckoutSession;
2426
use Magento\Quote\Model\Quote;
@@ -50,57 +52,57 @@ class MagentoDataHelper extends AbstractHelper
5052
/**
5153
* @var StoreManagerInterface
5254
*/
53-
private $storeManager;
55+
private StoreManagerInterface $storeManager;
5456

5557
/**
5658
* @var CustomerMetadataInterface
5759
*/
58-
private $customerMetadata;
60+
private CustomerMetadataInterface $customerMetadata;
5961

6062
/**
6163
* @var ProductRepositoryInterface
6264
*/
63-
private $productRepository;
65+
private ProductRepositoryInterface $productRepository;
6466

6567
/**
6668
* @var ProductIdentifier
6769
*/
68-
private $productIdentifier;
70+
private ProductIdentifier $productIdentifier;
6971

7072
/**
7173
* @var CheckoutSession
7274
*/
73-
private $checkoutSession;
75+
private CheckoutSession $checkoutSession;
7476

7577
/**
76-
* @var Quote
78+
* @var Quote|null
7779
*/
7880
private $quote;
7981

8082
/**
8183
* @var CustomerSession
8284
*/
83-
private $customerSession;
85+
private CustomerSession $customerSession;
8486

8587
/**
8688
* @var CategoryRepositoryInterface
8789
*/
88-
private $categoryRepository;
90+
private CategoryRepositoryInterface $categoryRepository;
8991

9092
/**
9193
* @var PricingHelper
9294
*/
93-
private $pricingHelper;
95+
private PricingHelper $pricingHelper;
9496

9597
/**
9698
* @var AddressFactory
9799
*/
98-
private $addressFactory;
100+
private AddressFactory $addressFactory;
99101

100102
/**
101103
* @var RegionFactory
102104
*/
103-
private $regionFactory;
105+
private RegionFactory $regionFactory;
104106

105107
/**
106108
* MagentoDataHelper constructor
@@ -173,23 +175,13 @@ public function getLastName(): string
173175
return $this->customerSession->getCustomer()->getLastname();
174176
}
175177

176-
/**
177-
* Return currently logged in users' Date of Birth.
178-
*
179-
* @return string
180-
*/
181-
public function getDateOfBirth(): string
182-
{
183-
return $this->customerSession->getCustomer()->getDob();
184-
}
185-
186178
/**
187179
* Return the product by the given sku
188180
*
189181
* @param string $productSku
190-
* @return \Magento\Catalog\Api\Data\ProductInterface | bool
182+
* @return ProductInterface | bool
191183
*/
192-
public function getProductBySku($productSku)
184+
public function getProductBySku(string $productSku)
193185
{
194186
try {
195187
return $this->productRepository->get($productSku);
@@ -199,10 +191,12 @@ public function getProductBySku($productSku)
199191
}
200192

201193
/**
202-
* @param $productId
203-
* @return false|\Magento\Catalog\Api\Data\ProductInterface
194+
* Get Product by ID
195+
*
196+
* @param mixed $productId
197+
* @return false|ProductInterface
204198
*/
205-
public function getProductById($productId): bool|\Magento\Catalog\Api\Data\ProductInterface
199+
public function getProductById($productId)
206200
{
207201
try {
208202
return $this->productRepository->getById($productId);
@@ -214,7 +208,7 @@ public function getProductById($productId): bool|\Magento\Catalog\Api\Data\Produ
214208
/**
215209
* Return the categories for the given product
216210
*
217-
* @param \Magento\Catalog\Model\Product $product
211+
* @param Product $product
218212
* @return string
219213
*/
220214
public function getCategoriesForProduct($product): string
@@ -248,7 +242,7 @@ public function getContentType(Product $product): string
248242
}
249243

250244
/**
251-
* Get content id
245+
* Get Content IDs (Product IDs)
252246
*
253247
* @param Product $product
254248
* @return bool|int|string
@@ -261,10 +255,10 @@ public function getContentId(Product $product)
261255
/**
262256
* Return the price for the given product
263257
*
264-
* @param \Magento\Catalog\Model\Product $product
258+
* @param Product $product
265259
* @return float
266260
*/
267-
public function getValueForProduct($product): float
261+
public function getValueForProduct(Product $product): float
268262
{
269263
$price = $product->getFinalPrice();
270264
return $this->pricingHelper->currency($price, false, false);
@@ -274,7 +268,8 @@ public function getValueForProduct($product): float
274268
* Return the currency used in the store
275269
*
276270
* @return string
277-
* @throws \Magento\Framework\Exception\NoSuchEntityException
271+
* @throws NoSuchEntityException
272+
* @throws LocalizedException
278273
*/
279274
public function getCurrency(): string
280275
{
@@ -389,7 +384,7 @@ public function getOrderContentIds(): array
389384
*
390385
* @return float|null
391386
*/
392-
public function getOrderTotal()
387+
public function getOrderTotal(): ?float
393388
{
394389
$order = $this->checkoutSession->getLastRealOrder();
395390
if (!$order) {
@@ -405,7 +400,6 @@ public function getOrderTotal()
405400

406401
/**
407402
* Return information about the last order items
408-
*
409403
* @link https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/custom-data/#contents
410404
*
411405
* @return array
@@ -465,7 +459,7 @@ public function getCurrentCustomer(): ?Customer
465459
/**
466460
* Return the address of a given customer
467461
*
468-
* @param object $customer
462+
* @param mixed $customer
469463
* @return Address
470464
*/
471465
public function getCustomerAddress($customer): Address
@@ -474,42 +468,12 @@ public function getCustomerAddress($customer): Address
474468
return $this->addressFactory->create()->load($customerAddressId);
475469
}
476470

477-
/**
478-
* Return the region's code for the given address
479-
*
480-
* @param object $address
481-
* @return string|null
482-
*/
483-
public function getRegionCodeForAddress($address): ?string
484-
{
485-
$region = $this->regionFactory->create()->load($address->getRegionId());
486-
if ($region) {
487-
return $region->getCode();
488-
} else {
489-
return null;
490-
}
491-
}
492-
493-
/**
494-
* Return the string representation of the customer gender
495-
*
496-
* @param object $customer
497-
* @return string|null
498-
*/
499-
public function getGenderAsString($customer): ?string
500-
{
501-
if ($customer->getGender()) {
502-
return $customer->getResource()->getAttribute('gender')->getSource()->getOptionText($customer->getGender());
503-
}
504-
return null;
505-
}
506-
507471
/**
508472
* Return all of the match keys that can be extracted from order information
509473
*
510474
* @return array
511-
* @throws \Magento\Framework\Exception\LocalizedException
512-
* @throws \Magento\Framework\Exception\NoSuchEntityException
475+
* @throws LocalizedException
476+
* @throws NoSuchEntityException
513477
*/
514478
public function getUserDataFromOrder(): array
515479
{
@@ -550,8 +514,8 @@ public function getUserDataFromOrder(): array
550514
* Return all of the match keys that can be extracted from user session
551515
*
552516
* @return array
553-
* @throws \Magento\Framework\Exception\LocalizedException
554-
* @throws \Magento\Framework\Exception\NoSuchEntityException
517+
* @throws LocalizedException
518+
* @throws NoSuchEntityException
555519
*/
556520
public function getUserDataFromSession(): array
557521
{
@@ -589,9 +553,9 @@ public function getUserDataFromSession(): array
589553
}
590554

591555
/**
592-
* Hash value
556+
* Get Hash value
593557
*
594-
* @param string $string
558+
* @param $string
595559
* @return string
596560
*/
597561
private function hashValue($string): string
@@ -603,6 +567,8 @@ private function hashValue($string): string
603567
* Get active quote
604568
*
605569
* @return Quote
570+
* @throws LocalizedException
571+
* @throws NoSuchEntityException
606572
*/
607573
public function getQuote(): Quote
608574
{

0 commit comments

Comments
 (0)