Completed
Push — develop ( b8f7b1...cea6ad )
by
unknown
07:05
created

ProviderOptionsFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 19 5
A createService() 0 4 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 * @author    [email protected]
9
 */
10
11
namespace Jobs\Factory\Options;
12
13
use Interop\Container\ContainerInterface;
14
use Jobs\Options\ProviderOptions;
15
use Zend\ServiceManager\FactoryInterface;
16
use Zend\ServiceManager\ServiceLocatorInterface;
17
18
class ProviderOptionsFactory implements FactoryInterface
19
{
20
    /**
21
     * Create an object
22
     *
23
     * @param  ContainerInterface $container
24
     * @param  string             $requestedName
25
     * @param  null|array         $options
26
     *
27
     * @return object
28
     * @throws ServiceNotFoundException if unable to resolve the service.
29
     * @throws ServiceNotCreatedException if an exception is raised when
30
     *     creating a service.
31
     * @throws ContainerException if any other error occurs
32
     */
33
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
34
    {
35
        $config = $container->get('Config');
36
        $multiposting = array_key_exists('multiposting', $config) ? $config['multiposting'] : array();
37
38
        $providerOptions = new ProviderOptions();
39
40
        if (array_key_exists('channels', $multiposting)) {
41
            foreach ($multiposting['channels'] as $channelName => $channel) {
42
                $channelOptions = $container->get('Jobs/Options/Channel');
43
                if (empty($channelOptions->key)) {
44
                    $channelOptions->key = $channelName;
45
                }
46
                $channelOptions->setFromArray($channel);
47
                $providerOptions->addChannel($channelOptions);
48
            }
49
        }
50
        return $providerOptions;
51
    }
52
53
    public function createService(ServiceLocatorInterface $serviceLocator)
54
    {
55
        return $this($serviceLocator, ProviderOptions::class);
56
    }
57
}
58