1
1
<?php
2
+ declare (strict_types=1 );
2
3
/**
3
4
* Copyright © Magento, Inc. All rights reserved.
4
5
* See COPYING.txt for license details.
@@ -58,22 +59,21 @@ public function __construct(
58
59
/**
59
60
* Prepare the Address Book section layout
60
61
*
61
- * @return $this
62
+ * @return void
62
63
* @throws \Magento\Framework\Exception\LocalizedException
63
64
*/
64
- protected function _prepareLayout ()
65
+ protected function _prepareLayout (): void
65
66
{
66
67
parent ::_prepareLayout ();
67
68
$ this ->preparePager ();
68
- return $ this ;
69
69
}
70
70
71
71
/**
72
72
* Generate and return "New Address" URL
73
73
*
74
74
* @return string
75
75
*/
76
- public function getAddAddressUrl ()
76
+ public function getAddAddressUrl (): string
77
77
{
78
78
return $ this ->getUrl ('customer/address/new ' , ['_secure ' => true ]);
79
79
}
@@ -83,7 +83,7 @@ public function getAddAddressUrl()
83
83
*
84
84
* @return string
85
85
*/
86
- public function getDeleteUrl ()
86
+ public function getDeleteUrl (): string
87
87
{
88
88
return $ this ->getUrl ('customer/address/delete ' );
89
89
}
@@ -96,7 +96,7 @@ public function getDeleteUrl()
96
96
* @param int $addressId
97
97
* @return string
98
98
*/
99
- public function getAddressEditUrl ($ addressId )
99
+ public function getAddressEditUrl ($ addressId ): string
100
100
{
101
101
return $ this ->getUrl ('customer/address/edit ' , ['_secure ' => true , 'id ' => $ addressId ]);
102
102
}
@@ -106,42 +106,35 @@ public function getAddressEditUrl($addressId)
106
106
*
107
107
* Will return array of address interfaces if customer have additional addresses and false in other case.
108
108
*
109
- * @return \Magento\Customer\Api\Data\AddressInterface[]|bool
109
+ * @return \Magento\Customer\Api\Data\AddressInterface[]
110
110
* @throws \Magento\Framework\Exception\LocalizedException
111
+ * @throws NoSuchEntityException
111
112
*/
112
- public function getAdditionalAddresses ()
113
+ public function getAdditionalAddresses (): array
113
114
{
114
- try {
115
- $ addresses = $ this ->getAddressCollection ();
116
- } catch (\Magento \Framework \Exception \NoSuchEntityException $ e ) {
117
- return false ;
118
- }
115
+ $ additional = [];
116
+ $ addresses = $ this ->getAddressCollection ();
119
117
$ primaryAddressIds = [$ this ->getDefaultBilling (), $ this ->getDefaultShipping ()];
120
118
foreach ($ addresses as $ address ) {
121
- if (!in_array ($ address ->getId (), $ primaryAddressIds )) {
119
+ if (!in_array (( int ) $ address ->getId (), $ primaryAddressIds, true )) {
122
120
$ additional [] = $ address ->getDataModel ();
123
121
}
124
122
}
125
- return empty ( $ additional ) ? false : $ additional ;
123
+ return $ additional ;
126
124
}
127
125
128
126
/**
129
127
* Get current customer
130
128
*
131
- * Check if customer is stored in current object and return it
132
- * or get customer by current customer ID through repository
129
+ * Return stored customer or get it from session
133
130
*
134
- * @return \Magento\Customer\Api\Data\CustomerInterface|null
131
+ * @return \Magento\Customer\Api\Data\CustomerInterface
135
132
*/
136
- public function getCustomer ()
133
+ public function getCustomer (): \ Magento \ Customer \ Api \ Data \ CustomerInterface
137
134
{
138
135
$ customer = $ this ->getData ('customer ' );
139
136
if ($ customer === null ) {
140
- try {
141
- $ customer = $ this ->currentCustomer ->getCustomer ();
142
- } catch (\Magento \Framework \Exception \NoSuchEntityException $ e ) {
143
- return null ;
144
- }
137
+ $ customer = $ this ->currentCustomer ->getCustomer ();
145
138
$ this ->setData ('customer ' , $ customer );
146
139
}
147
140
return $ customer ;
@@ -153,7 +146,7 @@ public function getCustomer()
153
146
* @param string|array $street
154
147
* @return string
155
148
*/
156
- public function getStreetAddress ($ street )
149
+ public function getStreetAddress ($ street ): string
157
150
{
158
151
if (is_array ($ street )) {
159
152
$ street = implode (', ' , $ street );
@@ -169,7 +162,7 @@ public function getStreetAddress($street)
169
162
* @param string $countryCode
170
163
* @return string
171
164
*/
172
- public function getCountryByCode ($ countryCode )
165
+ public function getCountryByCode ($ countryCode ): string
173
166
{
174
167
/** @var \Magento\Directory\Model\Country $country */
175
168
$ country = $ this ->countryFactory ->create ();
@@ -181,38 +174,38 @@ public function getCountryByCode($countryCode)
181
174
* Get default billing address
182
175
* Return address string if address found and null of not
183
176
*
184
- * @return string
177
+ * @return int
185
178
* @throws \Magento\Framework\Exception\LocalizedException
186
179
*/
187
- private function getDefaultBilling ()
180
+ private function getDefaultBilling (): int
188
181
{
189
182
$ customer = $ this ->getCustomer ();
190
183
191
- return $ customer ->getDefaultBilling ();
184
+ return ( int ) $ customer ->getDefaultBilling ();
192
185
}
193
186
194
187
195
188
/**
196
189
* Get default shipping address
197
190
* Return address string if address found and null of not
198
191
*
199
- * @return string
192
+ * @return int
200
193
* @throws \Magento\Framework\Exception\LocalizedException
201
194
*/
202
- private function getDefaultShipping ()
195
+ private function getDefaultShipping (): int
203
196
{
204
197
$ customer = $ this ->getCustomer ();
205
198
206
- return $ customer ->getDefaultShipping ();
199
+ return ( int ) $ customer ->getDefaultShipping ();
207
200
}
208
201
209
202
/**
210
203
* Get pager layout
211
204
*
212
- * @return void
205
+ * @return f
213
206
* @throws \Magento\Framework\Exception\LocalizedException
214
207
*/
215
- private function preparePager ()
208
+ private function preparePager (): void
216
209
{
217
210
$ addressCollection = $ this ->getAddressCollection ();
218
211
if (null !== $ addressCollection ) {
@@ -232,7 +225,7 @@ private function preparePager()
232
225
* @return \Magento\Customer\Model\ResourceModel\Address\Collection
233
226
* @throws NoSuchEntityException
234
227
*/
235
- private function getAddressCollection ()
228
+ private function getAddressCollection (): \ Magento \ Customer \ Model \ ResourceModel \ Address \ Collection
236
229
{
237
230
if (null === $ this ->addressCollection && $ this ->getCustomer ()) {
238
231
/** @var \Magento\Customer\Model\ResourceModel\Address\Collection $collection */
0 commit comments