Completed
Push — master ( 0a7e57...033978 )
by Thomas Mauro
02:31
created

AbstractFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 83.33%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 6
c 4
b 0
f 1
lcom 1
cbo 1
dl 0
loc 77
ccs 15
cts 18
cp 0.8333
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 4 1
A getOptions() 0 21 4
getOptionsClass() 0 1 ?
1
<?php
2
3
namespace Facile\SentryModule\Service;
4
5
use Interop\Container\ContainerInterface;
6
use RuntimeException;
7
use Zend\ServiceManager\FactoryInterface;
8
9
/**
10
 * Class AbstractFactory.
11
 */
12
abstract class AbstractFactory implements FactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\ServiceManager\FactoryInterface has been deprecated with message: Use Zend\ServiceManager\Factory\FactoryInterface instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $name;
18
19
    /**
20
     * @var \Zend\Stdlib\AbstractOptions
21
     */
22
    protected $options;
23
24
    /**
25
     * @var string
26
     */
27
    protected $configKey = 'facile';
28
29
    /**
30
     * @param string $name
31
     */
32 2
    public function __construct($name)
33
    {
34 2
        $this->name = $name;
35 2
    }
36
37
    /**
38
     * @return string
39
     */
40 2
    public function getName()
41
    {
42 2
        return $this->name;
43
    }
44
45
    /**
46
     * Gets options from configuration based on name.
47
     *
48
     * @param ContainerInterface $container
49
     * @param string             $key
50
     * @param null|string        $name
51
     *
52
     * @return \Zend\Stdlib\AbstractOptions
53
     * @throws \Interop\Container\Exception\NotFoundException
54
     * @throws \Interop\Container\Exception\ContainerException
55
     *
56
     * @throws \RuntimeException
57
     */
58 2
    public function getOptions(ContainerInterface $container, $key, $name = null)
59
    {
60 2
        if ($name === null) {
61 2
            $name = $this->getName();
62 2
        }
63
64
        /** @var array $options */
65 2
        $options = $container->get('config');
66 2
        $options = $options[$this->configKey]['sentry'];
67 2
        $options = isset($options[$key][$name]) ? $options[$key][$name] : null;
68
69 2
        if (null === $options) {
70
            throw new RuntimeException(
71
                sprintf('Options with name "%s" could not be found in "%s.%s"', $name, $this->configKey, $key)
72
            );
73
        }
74
75 2
        $optionsClass = $this->getOptionsClass();
76
77 2
        return new $optionsClass($options);
78
    }
79
80
    /**
81
     * Get the class name of the options associated with this factory.
82
     *
83
     * @abstract
84
     *
85
     * @return string
86
     */
87
    abstract public function getOptionsClass();
88
}
89