@@ -424,6 +424,8 @@ class AccountManagement implements AccountManagementInterface
424
424
* @param AllowedCountries|null $allowedCountriesReader
425
425
* @param SessionCleanerInterface|null $sessionCleaner
426
426
* @param AuthorizationInterface|null $authorization
427
+ * @param AuthenticationInterface|null $authentication
428
+ * @param Backend|null $eavValidator
427
429
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
428
430
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
429
431
* @SuppressWarnings(PHPMD.NPathComplexity)
@@ -465,7 +467,9 @@ public function __construct(
465
467
GetCustomerByToken $ getByToken = null ,
466
468
AllowedCountries $ allowedCountriesReader = null ,
467
469
SessionCleanerInterface $ sessionCleaner = null ,
468
- AuthorizationInterface $ authorization = null
470
+ AuthorizationInterface $ authorization = null ,
471
+ AuthenticationInterface $ authentication = null ,
472
+ Backend $ eavValidator = null
469
473
) {
470
474
$ this ->customerFactory = $ customerFactory ;
471
475
$ this ->eventManager = $ eventManager ;
@@ -506,22 +510,8 @@ public function __construct(
506
510
?: $ objectManager ->get (AllowedCountries::class);
507
511
$ this ->sessionCleaner = $ sessionCleaner ?? $ objectManager ->get (SessionCleanerInterface::class);
508
512
$ this ->authorization = $ authorization ?? $ objectManager ->get (AuthorizationInterface::class);
509
- }
510
-
511
- /**
512
- * Get authentication
513
- *
514
- * @return AuthenticationInterface
515
- */
516
- private function getAuthentication ()
517
- {
518
- if (!($ this ->authentication instanceof AuthenticationInterface)) {
519
- return \Magento \Framework \App \ObjectManager::getInstance ()->get (
520
- \Magento \Customer \Model \AuthenticationInterface::class
521
- );
522
- } else {
523
- return $ this ->authentication ;
524
- }
513
+ $ this ->authentication = $ authentication ?? $ objectManager ->get (AuthenticationInterface::class);
514
+ $ this ->eavValidator = $ eavValidator ?? $ objectManager ->get (Backend::class);
525
515
}
526
516
527
517
/**
@@ -617,11 +607,11 @@ public function authenticate($username, $password)
617
607
}
618
608
619
609
$ customerId = $ customer ->getId ();
620
- if ($ this ->getAuthentication () ->isLocked ($ customerId )) {
610
+ if ($ this ->authentication ->isLocked ($ customerId )) {
621
611
throw new UserLockedException (__ ('The account is locked. ' ));
622
612
}
623
613
try {
624
- $ this ->getAuthentication () ->authenticate ($ customerId , $ password );
614
+ $ this ->authentication ->authenticate ($ customerId , $ password );
625
615
} catch (InvalidEmailOrPasswordException $ e ) {
626
616
throw new InvalidEmailOrPasswordException (__ ('Invalid login or password. ' ));
627
617
}
@@ -1053,7 +1043,7 @@ public function changePasswordById($customerId, $currentPassword, $newPassword)
1053
1043
private function changePasswordForCustomer ($ customer , $ currentPassword , $ newPassword )
1054
1044
{
1055
1045
try {
1056
- $ this ->getAuthentication () ->authenticate ($ customer ->getId (), $ currentPassword );
1046
+ $ this ->authentication ->authenticate ($ customer ->getId (), $ currentPassword );
1057
1047
} catch (InvalidEmailOrPasswordException $ e ) {
1058
1048
throw new InvalidEmailOrPasswordException (
1059
1049
__ ("The password doesn't match this account. Verify the password and try again. " )
@@ -1084,19 +1074,6 @@ protected function createPasswordHash($password)
1084
1074
return $ this ->encryptor ->getHash ($ password , true );
1085
1075
}
1086
1076
1087
- /**
1088
- * Get EAV validator
1089
- *
1090
- * @return Backend
1091
- */
1092
- private function getEavValidator ()
1093
- {
1094
- if ($ this ->eavValidator === null ) {
1095
- $ this ->eavValidator = ObjectManager::getInstance ()->get (Backend::class);
1096
- }
1097
- return $ this ->eavValidator ;
1098
- }
1099
-
1100
1077
/**
1101
1078
* @inheritdoc
1102
1079
*/
@@ -1110,13 +1087,13 @@ public function validate(CustomerInterface $customer)
1110
1087
);
1111
1088
$ customer ->setAddresses ($ oldAddresses );
1112
1089
1113
- $ result = $ this ->getEavValidator () ->isValid ($ customerModel );
1114
- if ($ result === false && is_array ($ this ->getEavValidator () ->getMessages ())) {
1090
+ $ result = $ this ->eavValidator ->isValid ($ customerModel );
1091
+ if ($ result === false && is_array ($ this ->eavValidator ->getMessages ())) {
1115
1092
return $ validationResults ->setIsValid (false )->setMessages (
1116
1093
// phpcs:ignore Magento2.Functions.DiscouragedFunction
1117
1094
call_user_func_array (
1118
1095
'array_merge ' ,
1119
- array_values ($ this ->getEavValidator () ->getMessages ())
1096
+ array_values ($ this ->eavValidator ->getMessages ())
1120
1097
)
1121
1098
);
1122
1099
}
0 commit comments