SocialUserServiceFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 24 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