SocialUserServiceFactory::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 13
cts 13
cp 1
rs 9.536
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3
1
<?php
2
3
namespace Svycka\SocialUser\Service\Factory;
4
5
use Laminas\ServiceManager\Factory\FactoryInterface;
6
use Interop\Container\ContainerInterface;
7
use Svycka\SocialUser\LocalUserProviderInterface;
8
use Svycka\SocialUser\Service\SocialUserService;
9
use Svycka\SocialUser\Storage\SocialUserStorageInterface;
10
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
11
12
/**
13
 * @author Vytautas Stankus <[email protected]>
14
 * @license MIT
15
 */
16
final class SocialUserServiceFactory implements FactoryInterface
17
{
18 3
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
19
    {
20 3
        $config = $container->get('config')['svycka_social_user'];
21
22 3
        $localUserProvider = $container->get($config['local_user_provider']);
23
24 3
        if (!$localUserProvider instanceof LocalUserProviderInterface) {
25 1
            throw new ServiceNotCreatedException(sprintf(
26 1
                'Invalid "local_user_provider" specified expected class name with implements "%s"',
27 1
                LocalUserProviderInterface::class
28
            ));
29
        }
30
31 2
        $storage = $container->get($config['social_user_storage']);
32
33 2
        if (!$storage instanceof SocialUserStorageInterface) {
34 1
            throw new ServiceNotCreatedException(sprintf(
35 1
                'Invalid "social_user_storage" specified expected class name with implements "%s"',
36 1
                SocialUserStorageInterface::class
37
            ));
38
        }
39
40 1
        return new SocialUserService($localUserProvider, $storage);
41
    }
42
}
43