Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 3feaeaf

Browse files
committed
Minor refactor: extract method
Extracts the method `discoverAuthenticationService()` from `IdentityFactory::__invoke()`, allowing removal of an if/else, and simplifying the logic of the main factory method.
1 parent 2554cf2 commit 3feaeaf

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/Helper/Service/IdentityFactory.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Zend Framework (http://framework.zend.com/)
44
*
55
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
6+
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (http://www.zend.com)
77
* @license http://framework.zend.com/license/new-bsd New BSD License
88
*/
99

@@ -32,12 +32,13 @@ public function __invoke(ContainerInterface $container, $name, array $options =
3232
if (! method_exists($container, 'configure')) {
3333
$container = $container->getServiceLocator();
3434
}
35+
3536
$helper = new Identity();
36-
if ($container->has(AuthenticationService::class)) {
37-
$helper->setAuthenticationService($container->get(AuthenticationService::class));
38-
} elseif ($container->has(AuthenticationServiceInterface::class)) {
39-
$helper->setAuthenticationService($container->get(AuthenticationServiceInterface::class));
37+
38+
if (null !== ($authenticationService = $this->discoverAuthenticationService($container))) {
39+
$helper->setAuthenticationService($authenticationService);
4040
}
41+
4142
return $helper;
4243
}
4344

@@ -51,4 +52,18 @@ public function createService(ServiceLocatorInterface $serviceLocator, $rName =
5152
{
5253
return $this($serviceLocator, $cName);
5354
}
55+
56+
/**
57+
* @return null|AuthenticationServiceInterface
58+
*/
59+
private function discoverAuthenticationService(ContainerInterface $container)
60+
{
61+
if ($container->has(AuthenticationService::class)) {
62+
return $container->get(AuthenticationService::class);
63+
}
64+
65+
return $container->has(AuthenticationServiceInterface::class)
66+
? $container->get(AuthenticationServiceInterface::class)
67+
: null;
68+
}
5469
}

0 commit comments

Comments
 (0)