Completed
Pull Request — master (#494)
by Thomas Mauro
28:51
created

YumlControllerFactory::__invoke()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 16
rs 9.4285
cc 3
eloc 8
nc 2
nop 3
1
<?php
2
3
namespace DoctrineORMModule\Yuml;
4
5
use Interop\Container\ContainerInterface;
6
use Interop\Container\Exception\ContainerException;
7
use Zend\ServiceManager\AbstractPluginManager;
8
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
9
use Zend\ServiceManager\Exception\ServiceNotFoundException;
10
use Zend\ServiceManager\FactoryInterface;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
use Zend\Http\Client;
13
14
class YumlControllerFactory 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...
15
{
16
17
    /**
18
     * Create service
19
     *
20
     * @param ServiceLocatorInterface $serviceLocator
21
     * @return mixed
22
     */
23
    public function createService(ServiceLocatorInterface $serviceLocator)
24
    {
25
        if ($serviceLocator instanceof AbstractPluginManager) {
26
            $serviceLocator = $serviceLocator->getServiceLocator() ?: $serviceLocator;
0 ignored issues
show
Deprecated Code introduced by
The method Zend\ServiceManager\Serv...er::getServiceLocator() has been deprecated with message: since 3.0.0. Factories using 3.0 should use the container instance passed to the factory instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
27
        }
28
29
        return $this($serviceLocator, YumlController::class);
30
    }
31
32
    /**
33
     * Create an object
34
     *
35
     * @param  ContainerInterface $container
36
     * @param  string             $requestedName
37
     * @param  null|array         $options
38
     * @return object
39
     * @throws ServiceNotFoundException if unable to resolve the service.
40
     * @throws ServiceNotCreatedException if an exception is raised when
41
     *     creating a service.
42
     * @throws ContainerException if any other error occurs
43
     */
44
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
45
    {
46
        $config = $container->get('config');
47
48
        if (! isset($config['zenddevelopertools']['toolbar']['enabled'])
49
            || !$config['zenddevelopertools']['toolbar']['enabled']
50
        ) {
51
            throw new ServiceNotFoundException(
52
                'Service DoctrineORMModule\\Yuml\\YumlController could not be found'
53
            );
54
        }
55
56
        return new YumlController(
57
            new Client('http://yuml.me/diagram/plain/class/', ['timeout' => 30])
58
        );
59
    }
60
}
61