ModuleOptionsFactory::createService()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 8.7624
cc 5
eloc 10
nc 4
nop 1
1
<?php
2
/**
3
 * ModuleOptionsFactory
4
 *
5
 * @category  AxalianAchievements\ServiceFactory\Options
6
 * @package   AxalianAchievements\ServiceFactory\Options
7
 * @author    Michel Maas <[email protected]>
8
 */
9
10
namespace AxalianAchievements\ServiceFactory\Options;
11
12
use AxalianAchievements\Exception\RuntimeException;
13
use AxalianAchievements\Options\ModuleOptions;
14
use Zend\ServiceManager\FactoryInterface;
15
use Zend\ServiceManager\ServiceLocatorInterface;
16
17
class ModuleOptionsFactory implements FactoryInterface
18
{
19
    /**
20
     * Create service
21
     *
22
     * @param ServiceLocatorInterface $serviceLocator
23
     * @throws \AxalianAchievements\Exception\RuntimeException
24
     * @return ModuleOptions
25
     */
26
    public function createService(ServiceLocatorInterface $serviceLocator)
27
    {
28
        /** @var ModuleOptions $moduleOptions */
29
        $config = $serviceLocator->get('Config');
30
31
        if (!isset($config['axalian_achievements'])) {
32
            throw new RuntimeException('No valid "axalian_achievements" config set');
33
        }
34
35
        if (!isset($config['axalian_achievements']['achievement_providers'])) {
36
            throw new RuntimeException('No valid "achievement_providers" config set in "axalian_achievements"');
37
        }
38
39
        if (!isset($config['axalian_achievements']['storage_adapter']) ||
40
            empty($config['axalian_achievements']['storage_adapter'])
41
        ) {
42
            throw new RuntimeException('No valid "storage_adapter" config set in "axalian_achievements"');
43
        }
44
45
        return new ModuleOptions($config['axalian_achievements']);
46
    }
47
}
48