Skip to content

Commit 7b41128

Browse files
AC-2574 - updated variables scope and method return strict type
1 parent 3b0f2a3 commit 7b41128

File tree

14 files changed

+114
-136
lines changed

14 files changed

+114
-136
lines changed

app/code/Magento/GoogleGtag/Block/Code.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,34 @@
99

1010
namespace Magento\GoogleGtag\Block;
1111

12+
use Magento\Framework\View\Element\Template;
1213
use Magento\Framework\View\Element\Template\Context;
13-
use Magento\GoogleGtag\Helper\Data;
14+
use Magento\GoogleGtag\Helper\GtagConfiguration;
1415

1516
/**
1617
* Google Ads Code block
1718
*
1819
* @api
1920
* @since 100.0.2
2021
*/
21-
class Code extends \Magento\Framework\View\Element\Template
22+
class Code extends Template
2223
{
2324
/**
24-
* @var Data
25+
* @var GtagConfiguration
2526
*/
26-
protected $_googleGtagData;
27+
private $googleGtagConfig;
2728

2829
/**
2930
* @param Context $context
30-
* @param Data $googleGtagData
31+
* @param GtagConfiguration $googleGtagConfig
3132
* @param array $data
3233
*/
3334
public function __construct(
3435
Context $context,
35-
Data $googleGtagData,
36+
GtagConfiguration $googleGtagConfig,
3637
array $data = []
3738
) {
38-
$this->_googleGtagData = $googleGtagData;
39+
$this->googleGtagConfig = $googleGtagConfig;
3940
parent::__construct($context, $data);
4041
}
4142

@@ -44,18 +45,18 @@ public function __construct(
4445
*
4546
* @return string
4647
*/
47-
protected function _toHtml()
48+
protected function _toHtml(): string
4849
{
49-
return $this->_googleGtagData->isGoogleAdwordsActive() ? parent::_toHtml() : '';
50+
return $this->googleGtagConfig->isGoogleAdwordsActive() ? parent::_toHtml() : '';
5051
}
5152

5253
/**
5354
* Return helper
5455
*
55-
* @return Data
56+
* @return GtagConfiguration
5657
*/
57-
public function getHelper()
58+
public function getHelper(): GtagConfiguration
5859
{
59-
return $this->_googleGtagData;
60+
return $this->googleGtagConfig;
6061
}
6162
}

app/code/Magento/GoogleGtag/Block/Ga.php

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
namespace Magento\GoogleGtag\Block;
99

1010
use Magento\Cookie\Helper\Cookie;
11-
use Magento\Framework\App\ObjectManager;
1211
use Magento\Framework\View\Element\Template;
1312
use Magento\Framework\View\Element\Template\Context;
14-
use Magento\GoogleGtag\Helper\Data;
13+
use Magento\GoogleGtag\Helper\GtagConfiguration;
1514
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
1615
use Magento\Store\Model\ScopeInterface;
1716

@@ -23,14 +22,14 @@
2322
class Ga extends Template
2423
{
2524
/**
26-
* @var Data
25+
* @var GtagConfiguration
2726
*/
28-
protected $_googleGtagData = null;
27+
private $googleGtagConfig;
2928

3029
/**
3130
* @var CollectionFactory
3231
*/
33-
protected $_salesOrderCollection;
32+
private $salesOrderCollection;
3433

3534
/**
3635
* @var Cookie
@@ -40,20 +39,20 @@ class Ga extends Template
4039
/**
4140
* @param Context $context
4241
* @param CollectionFactory $salesOrderCollection
43-
* @param Data $googleGtagData
42+
* @param GtagConfiguration $googleGtagConfig
4443
* @param array $data
45-
* @param Cookie|null $cookieHelper
44+
* @param Cookie $cookieHelper
4645
*/
4746
public function __construct(
4847
Context $context,
4948
CollectionFactory $salesOrderCollection,
50-
Data $googleGtagData,
51-
array $data = [],
52-
Cookie $cookieHelper = null
49+
GtagConfiguration $googleGtagConfig,
50+
Cookie $cookieHelper,
51+
array $data = []
5352
) {
54-
$this->_googleGtagData = $googleGtagData;
55-
$this->_salesOrderCollection = $salesOrderCollection;
56-
$this->cookieHelper = $cookieHelper ?: ObjectManager::getInstance()->get(Cookie::class);
53+
$this->googleGtagConfig = $googleGtagConfig;
54+
$this->salesOrderCollection = $salesOrderCollection;
55+
$this->cookieHelper = $cookieHelper;
5756
parent::__construct($context, $data);
5857
}
5958

@@ -63,27 +62,27 @@ public function __construct(
6362
* @param string $path
6463
* @return mixed
6564
*/
66-
public function getConfig($path)
65+
public function getConfig($path): string
6766
{
6867
return $this->_scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE);
6968
}
7069

7170
/**
7271
* Get helper
7372
*
74-
* @return Data|null
73+
* @return GtagConfiguration
7574
*/
76-
public function getHelper()
75+
public function getHelper(): GtagConfiguration
7776
{
78-
return $this->_googleGtagData;
77+
return $this->googleGtagConfig;
7978
}
8079

8180
/**
8281
* Get a specific page name (may be customized via layout)
8382
*
8483
* @return string|null
8584
*/
86-
public function getPageName()
85+
public function getPageName(): ?string
8786
{
8887
return $this->_getData('page_name');
8988
}
@@ -95,7 +94,7 @@ public function getPageName()
9594
*/
9695
protected function _toHtml()
9796
{
98-
if (!$this->_googleGtagData->isGoogleAnalyticsAvailable()) {
97+
if (!$this->googleGtagConfig->isGoogleAnalyticsAvailable()) {
9998
return '';
10099
}
101100

@@ -107,19 +106,19 @@ protected function _toHtml()
107106
*
108107
* @return bool
109108
*/
110-
public function isCookieRestrictionModeEnabled()
109+
public function isCookieRestrictionModeEnabled(): bool
111110
{
112-
return $this->cookieHelper->isCookieRestrictionModeEnabled();
111+
return (bool) $this->cookieHelper->isCookieRestrictionModeEnabled();
113112
}
114113

115114
/**
116115
* Return current website id.
117116
*
118117
* @return int
119118
*/
120-
public function getCurrentWebsiteId()
119+
public function getCurrentWebsiteId(): int
121120
{
122-
return $this->_storeManager->getWebsite()->getId();
121+
return (int) $this->_storeManager->getWebsite()->getId();
123122
}
124123

125124
/**
@@ -128,14 +127,14 @@ public function getCurrentWebsiteId()
128127
* @link https://developers.google.com/analytics/devguides/collection/gtagjs
129128
* @link https://developers.google.com/analytics/devguides/collection/ga4
130129
*
131-
* @param string $accountId
130+
* @param string $measurementId
132131
* @return array
133132
*/
134-
public function getPageTrackingData($accountId)
133+
public function getPageTrackingData($measurementId): array
135134
{
136135
return [
137136
'optPageUrl' => $this->getOptPageUrl(),
138-
'accountId' => $this->escapeHtmlAttr($accountId, false)
137+
'measurementId' => $this->escapeHtmlAttr($measurementId, false)
139138
];
140139
}
141140

@@ -150,32 +149,32 @@ public function getPageTrackingData($accountId)
150149
* @return array
151150
* @since 100.2.0
152151
*/
153-
public function getOrdersTrackingData()
152+
public function getOrdersTrackingData(): array
154153
{
155154
$result = [];
156155
$orderIds = $this->getOrderIds();
157156
if (empty($orderIds) || !is_array($orderIds)) {
158157
return $result;
159158
}
160159

161-
$collection = $this->_salesOrderCollection->create();
160+
$collection = $this->salesOrderCollection->create();
162161
$collection->addFieldToFilter('entity_id', ['in' => $orderIds]);
163162

164163
foreach ($collection as $order) {
165164
foreach ($order->getAllVisibleItems() as $item) {
166165
$result['products'][] = [
167166
'item_id' => $this->escapeJsQuote($item->getSku()),
168167
'item_name' => $this->escapeJsQuote($item->getName()),
169-
'price' => $this->_googleGtagData->formatToDec((float) $item->getPrice()),
168+
'price' => $this->googleGtagConfig->formatToDec((float) $item->getPrice()),
170169
'quantity' => (int)$item->getQtyOrdered(),
171170
];
172171
}
173172
$result['orders'][] = [
174173
'transaction_id' => $order->getIncrementId(),
175174
'affiliation' => $this->escapeJsQuote($this->_storeManager->getStore()->getFrontendName()),
176-
'value' => $this->_googleGtagData->formatToDec((float) $order->getGrandTotal()),
177-
'tax' => $this->_googleGtagData->formatToDec((float) $order->getTaxAmount()),
178-
'shipping' => $this->_googleGtagData->formatToDec((float) $order->getShippingAmount()),
175+
'value' => $this->googleGtagConfig->formatToDec((float) $order->getGrandTotal()),
176+
'tax' => $this->googleGtagConfig->formatToDec((float) $order->getTaxAmount()),
177+
'shipping' => $this->googleGtagConfig->formatToDec((float) $order->getShippingAmount()),
179178
];
180179
$result['currency'] = $order->getOrderCurrencyCode();
181180
}
@@ -187,7 +186,7 @@ public function getOrdersTrackingData()
187186
*
188187
* @return string
189188
*/
190-
private function getOptPageUrl()
189+
private function getOptPageUrl(): string
191190
{
192191
$optPageURL = '';
193192
$pageName = $this->getPageName() !== null ? trim($this->getPageName()) : '';

app/code/Magento/GoogleGtag/Block/Head.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use Magento\Framework\View\Element\Template;
1111
use Magento\Framework\View\Element\Template\Context;
12-
use Magento\GoogleGtag\Helper\Data;
12+
use Magento\GoogleGtag\Helper\GtagConfiguration;
1313

1414
/**
1515
* Google Ads Head block
@@ -19,21 +19,21 @@
1919
class Head extends Template
2020
{
2121
/**
22-
* @var Data
22+
* @var GtagConfiguration
2323
*/
24-
protected $googleGtagData;
24+
private $googleGtagConfig;
2525

2626
/**
2727
* @param Context $context
28-
* @param Data $googleGtagData
28+
* @param GtagConfiguration $googleGtagConfig
2929
* @param array $data
3030
*/
3131
public function __construct(
3232
Context $context,
33-
Data $googleGtagData,
33+
GtagConfiguration $googleGtagConfig,
3434
array $data = []
3535
) {
36-
$this->googleGtagData = $googleGtagData;
36+
$this->googleGtagConfig = $googleGtagConfig;
3737
parent::__construct($context, $data);
3838
}
3939

@@ -44,16 +44,16 @@ public function __construct(
4444
*/
4545
protected function _toHtml()
4646
{
47-
return $this->googleGtagData->isGoogleAdwordsActive() ? parent::_toHtml() : '';
47+
return $this->googleGtagConfig->isGoogleAdwordsActive() ? parent::_toHtml() : '';
4848
}
4949

5050
/**
5151
* Return helper
5252
*
53-
* @return Data
53+
* @return GtagConfiguration
5454
*/
55-
public function getHelper()
55+
public function getHelper(): GtagConfiguration
5656
{
57-
return $this->googleGtagData;
57+
return $this->googleGtagConfig;
5858
}
5959
}

app/code/Magento/GoogleGtag/Helper/Data.php renamed to app/code/Magento/GoogleGtag/Helper/GtagConfiguration.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @api
1818
*/
19-
class Data extends AbstractHelper
19+
class GtagConfiguration extends AbstractHelper
2020
{
2121
/**
2222
* Config paths for using throughout the code
@@ -52,21 +52,21 @@ class Data extends AbstractHelper
5252
* @param null|string|bool|int|Store $store
5353
* @return bool
5454
*/
55-
public function isGoogleAnalyticsAvailable($store = null)
55+
public function isGoogleAnalyticsAvailable($store = null): bool
5656
{
5757
return $this->scopeConfig->isSetFlag(
5858
self::XML_PATH_ACTIVE,
5959
ScopeInterface::SCOPE_STORE,
6060
$store
61-
) && $this->getAccountId();
61+
) && $this->getMeasurementId();
6262
}
6363

6464
/**
6565
* Get Account Id, depending on property type Tracking Id (UA) or Measurement Id (GA4)
6666
*
6767
* @return string
6868
*/
69-
public function getAccountId()
69+
public function getMeasurementId(): string
7070
{
7171
return (string)$this->scopeConfig->getValue(
7272
self::XML_PATH_MEASUREMENT_ID,
@@ -79,7 +79,7 @@ public function getAccountId()
7979
*
8080
* @return bool
8181
*/
82-
public function isGoogleAdwordsActive()
82+
public function isGoogleAdwordsActive(): bool
8383
{
8484
return $this->scopeConfig->isSetFlag(
8585
self::XML_PATH_ADWORD_ACTIVE,
@@ -94,7 +94,7 @@ public function isGoogleAdwordsActive()
9494
*
9595
* @return bool
9696
*/
97-
public function isGoogleAdwordsConfigurable()
97+
public function isGoogleAdwordsConfigurable(): bool
9898
{
9999
return $this->scopeConfig->isSetFlag(
100100
self::XML_PATH_ADWORD_ACTIVE,
@@ -107,7 +107,7 @@ public function isGoogleAdwordsConfigurable()
107107
*
108108
* @return string
109109
*/
110-
public function getConversionGtagGlobalSiteTagSrc()
110+
public function getConversionGtagGlobalSiteTagSrc(): string
111111
{
112112
$siteSrc = self::GTAG_GLOBAL_SITE_TAG_SRC;
113113
$cId = $this->getConversionId();
@@ -119,7 +119,7 @@ public function getConversionGtagGlobalSiteTagSrc()
119119
*
120120
* @return string
121121
*/
122-
public function getConversionId()
122+
public function getConversionId(): string
123123
{
124124
return (string)$this->scopeConfig->getValue(
125125
self::XML_PATH_CONVERSION_ID,
@@ -132,7 +132,7 @@ public function getConversionId()
132132
*
133133
* @return string
134134
*/
135-
public function getConversionLabel()
135+
public function getConversionLabel(): string
136136
{
137137
return $this->scopeConfig->getValue(
138138
self::XML_PATH_CONVERSION_LABEL,

0 commit comments

Comments
 (0)