Completed
Pull Request — master (#2)
by Toni
12:51
created

RolloutCollectorFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createService() 0 4 1
A __invoke() 0 25 3
1
<?php
2
/*
3
 * This file is part of the Adlogix package.
4
 *
5
 * (c) Allan Segebarth <[email protected]>
6
 * (c) Jean-Jacques Courtens <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Adlogix\Zf2Rollout\Service\Factory;
13
14
use Collector\RolloutCollector;
15
use Interop\Container\ContainerInterface;
16
use Opensoft\Rollout\Rollout;
17
use Opensoft\Rollout\RolloutUserInterface;
18
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
19
use Zend\ServiceManager\FactoryInterface;
20
use Zend\ServiceManager\ServiceLocatorInterface;
21
22
/**
23
 * @author Toni Van de Voorde <[email protected]>
24
 */
25
final class RolloutCollectorFactory implements FactoryInterface
26
{
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function createService(ServiceLocatorInterface $serviceLocator)
32
    {
33
        return $this($serviceLocator, null);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
40
    {
41
        /** @var array $config */
42
        $config = $container->get('zf2_rollout_config');
43
44
45
        /** @var Rollout $rollout */
46
        $rollout = $container->get('zf2_rollout');
47
48
        $rolloutUserServiceId = $config['user_service'];
49
50
        if (!isset($rolloutUserServiceId)) {
51
            throw new ServiceNotCreatedException(sprintf('You must define a service for rollout user_service.'));
52
        }
53
54
        if (!$container->has($rolloutUserServiceId)) {
55
            throw new ServiceNotCreatedException(sprintf('Defined rollout user_service \'%s\' is not configured!',
56
                $rolloutUserServiceId));
57
        }
58
59
        /** @var RolloutUserInterface $rolloutUser */
60
        $rolloutUser = $container->get($rolloutUserServiceId);
61
62
        return new RolloutCollector($rollout, $rolloutUser);
63
    }
64
}
65