SentryLoggerConfigFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 33
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 2
1
<?php
2
3
namespace Dasao\SentryLogger\Log;
4
5
use Interop\Container\ContainerInterface;
6
use Psr\Container\ContainerExceptionInterface;
7
use Psr\Container\NotFoundExceptionInterface;
8
use ReflectionException;
9
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
10
use Zend\ServiceManager\Factory\FactoryInterface;
11
12
/**
13
 * Class SentryLoggerConfigFactory
14
 *
15
 * PHP Version 7
16
 *
17
 * @category  PHP
18
 * @package   Dasao\SentryLogger\Log
19
 * @author    Dasao <[email protected]>
20
 * @copyright 2014-2017 Dasao
21
 * @license   Proprietary http://www.das-ao.com
22
 */
23
class SentryLoggerConfigFactory implements FactoryInterface
24
{
25
    /**
26
     * Invoke the factory.
27
     *
28
     *
29
     * @param ContainerInterface $container     The DI container.
30
     * @param string             $requestedName The requested class name.
31
     * @param null|array         $options       Optional options.
32
     *
33
     * @return SentryLoggerConfigInterface
34
     *
35
     * @throws ContainerExceptionInterface Error while retrieving the entry.
36
     * @throws NotFoundExceptionInterface If service was not found in container.
37
     * @throws ServiceNotCreatedException If sentry config is not available.
38
     * @throws ReflectionException Error on reflection.
39
     */
40
    public function __invoke(
41
        ContainerInterface $container,
42
        $requestedName,
43
        array $options = null
44
    ) : SentryLoggerConfigInterface {
45
        /** @var array $config */
46
        $config = $container->get('config');
47
48
        if (isset($config['sentry'])) {
49
            $sentryLoggerConfig = new SentryLoggerConfig();
50
            $sentryLoggerConfig->exchangeArray($config['sentry']);
51
52
            return $sentryLoggerConfig;
53
        }
54
55
        throw new ServiceNotCreatedException('Sentry config not available.');
56
    }
57
}
58