Completed
Push — master ( 3bf9b5...74e13e )
by Thomas Mauro
02:41
created

SentryFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 59
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 12 3
A createService() 0 4 1
A setCreationOptions() 0 4 1
1
<?php
2
3
namespace Facile\SentryModule\Log\Writer;
4
5
use Interop\Container\ContainerInterface;
6
use Interop\Container\Exception\ContainerException;
7
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
8
use Zend\ServiceManager\Exception\ServiceNotFoundException;
9
use Zend\ServiceManager\FactoryInterface;
10
use Zend\ServiceManager\ServiceLocatorInterface;
11
12
class SentryFactory 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
     * zend-servicemanager v2 support for invocation options.
16
     *
17
     * @param array
18
     */
19
    protected $creationOptions;
20
21
    /**
22
     * Create an object
23
     *
24
     * @param  ContainerInterface $container
25
     * @param  string             $requestedName
26
     * @param  null|array         $options
27
     * @return Sentry
28
     * @throws \Zend\Log\Exception\InvalidArgumentException
29
     * @throws \Interop\Container\Exception\NotFoundException
30
     * @throws \RuntimeException
31
     * @throws ServiceNotFoundException if unable to resolve the service.
32
     * @throws ServiceNotCreatedException if an exception is raised when
33
     *     creating a service.
34
     * @throws ContainerException if any other error occurs
35
     */
36 2
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
37
    {
38 2
        $options = $options ?: [];
39
40 2
        if (!array_key_exists('client', $options)) {
41 1
            throw new \RuntimeException('No client specified');
42
        }
43
44 1
        $options['client'] = $container->get($options['client']);
45
46 1
        return new Sentry($options);
47
    }
48
49
    /**
50
     * Create service
51
     *
52
     * @param ServiceLocatorInterface $serviceLocator
53
     * @return Sentry
54
     */
55 2
    public function createService(ServiceLocatorInterface $serviceLocator)
56
    {
57 2
        return $this($serviceLocator, Sentry::class, $this->creationOptions);
58
    }
59
60
    /**
61
     * zend-servicemanager v2 support for invocation options.
62
     *
63
     * @param array $options
64
     * @return void
65
     */
66 1
    public function setCreationOptions(array $options)
67
    {
68 1
        $this->creationOptions = $options;
69 1
    }
70
}
71