@@ -424,6 +424,8 @@ class AccountManagement implements AccountManagementInterface
424424 * @param AllowedCountries|null $allowedCountriesReader
425425 * @param SessionCleanerInterface|null $sessionCleaner
426426 * @param AuthorizationInterface|null $authorization
427+ * @param AuthenticationInterface|null $authentication
428+ * @param Backend|null $eavValidator
427429 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
428430 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
429431 * @SuppressWarnings(PHPMD.NPathComplexity)
@@ -465,7 +467,9 @@ public function __construct(
465467 GetCustomerByToken $ getByToken = null ,
466468 AllowedCountries $ allowedCountriesReader = null ,
467469 SessionCleanerInterface $ sessionCleaner = null ,
468- AuthorizationInterface $ authorization = null
470+ AuthorizationInterface $ authorization = null ,
471+ AuthenticationInterface $ authentication = null ,
472+ Backend $ eavValidator = null
469473 ) {
470474 $ this ->customerFactory = $ customerFactory ;
471475 $ this ->eventManager = $ eventManager ;
@@ -506,22 +510,8 @@ public function __construct(
506510 ?: $ objectManager ->get (AllowedCountries::class);
507511 $ this ->sessionCleaner = $ sessionCleaner ?? $ objectManager ->get (SessionCleanerInterface::class);
508512 $ 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);
525515 }
526516
527517 /**
@@ -617,11 +607,11 @@ public function authenticate($username, $password)
617607 }
618608
619609 $ customerId = $ customer ->getId ();
620- if ($ this ->getAuthentication () ->isLocked ($ customerId )) {
610+ if ($ this ->authentication ->isLocked ($ customerId )) {
621611 throw new UserLockedException (__ ('The account is locked. ' ));
622612 }
623613 try {
624- $ this ->getAuthentication () ->authenticate ($ customerId , $ password );
614+ $ this ->authentication ->authenticate ($ customerId , $ password );
625615 } catch (InvalidEmailOrPasswordException $ e ) {
626616 throw new InvalidEmailOrPasswordException (__ ('Invalid login or password. ' ));
627617 }
@@ -1053,7 +1043,7 @@ public function changePasswordById($customerId, $currentPassword, $newPassword)
10531043 private function changePasswordForCustomer ($ customer , $ currentPassword , $ newPassword )
10541044 {
10551045 try {
1056- $ this ->getAuthentication () ->authenticate ($ customer ->getId (), $ currentPassword );
1046+ $ this ->authentication ->authenticate ($ customer ->getId (), $ currentPassword );
10571047 } catch (InvalidEmailOrPasswordException $ e ) {
10581048 throw new InvalidEmailOrPasswordException (
10591049 __ ("The password doesn't match this account. Verify the password and try again. " )
@@ -1084,19 +1074,6 @@ protected function createPasswordHash($password)
10841074 return $ this ->encryptor ->getHash ($ password , true );
10851075 }
10861076
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-
11001077 /**
11011078 * @inheritdoc
11021079 */
@@ -1110,13 +1087,13 @@ public function validate(CustomerInterface $customer)
11101087 );
11111088 $ customer ->setAddresses ($ oldAddresses );
11121089
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 ())) {
11151092 return $ validationResults ->setIsValid (false )->setMessages (
11161093 // phpcs:ignore Magento2.Functions.DiscouragedFunction
11171094 call_user_func_array (
11181095 'array_merge ' ,
1119- array_values ($ this ->getEavValidator () ->getMessages ())
1096+ array_values ($ this ->eavValidator ->getMessages ())
11201097 )
11211098 );
11221099 }
0 commit comments