ConnectionStatusDelegatorFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 43
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 1
A createDelegatorWithName() 0 4 1
1
<?php
2
3
namespace PamiModule\Service;
4
5
use Interop\Container\ContainerInterface;
6
use Interop\Container\Exception\ContainerException;
7
use PamiModule\Listener\ConnectionStatusListener;
8
use Zend\ServiceManager\DelegatorFactoryInterface;
9
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
10
use Zend\ServiceManager\Exception\ServiceNotFoundException;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
13
/**
14
 * Class ConnectionStatusDelegatorFactory.
15
 */
16
class ConnectionStatusDelegatorFactory implements DelegatorFactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\ServiceManager\DelegatorFactoryInterface has been deprecated with message: Use Zend\ServiceManager\Factory\DelegatorFactoryInterface 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...
17
{
18
    /**
19
     * A factory that creates delegates of a given service.
20
     *
21
     * @param ContainerInterface $container
22
     * @param string             $name
23
     * @param callable           $callback
24
     * @param null|array         $options
25
     *
26
     * @throws ServiceNotFoundException   if unable to resolve the service
27
     * @throws ServiceNotCreatedException if an exception is raised when
28
     *                                    creating a service
29
     * @throws ContainerException         if any other error occurs
30
     *
31
     * @return object
32
     */
33 1
    public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null)
34
    {
35
        /** @var \PamiModule\Service\Client $client */
36 1
        $client = $callback();
37
38 1
        $listener = $container->get(ConnectionStatusListener::class);
39 1
        $listener->attach($client->getEventManager(), 10000);
40
41 1
        return $client;
42
    }
43
44
    /**
45
     * A factory that creates delegates of a given service.
46
     *
47
     * @param ServiceLocatorInterface $serviceLocator the service locator which requested the service
48
     * @param string                  $name           the normalized service name
49
     * @param string                  $requestedName  the requested service name
50
     * @param callable                $callback       the callback that is responsible for creating the service
51
     *
52
     * @return \PamiModule\Service\Client
53
     */
54 1
    public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback)
55
    {
56 1
        return $this($serviceLocator, $requestedName, $callback);
57
    }
58
}
59