Completed
Pull Request — master (#494)
by Thomas Mauro
29:59 queued 19:46
created

YumlControllerFactory::createService()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 4
nc 3
nop 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace DoctrineORMModule\Yuml;
21
22
use Interop\Container\ContainerInterface;
23
use Interop\Container\Exception\ContainerException;
24
use Zend\ServiceManager\AbstractPluginManager;
25
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
26
use Zend\ServiceManager\Exception\ServiceNotFoundException;
27
use Zend\ServiceManager\FactoryInterface;
28
use Zend\ServiceManager\ServiceLocatorInterface;
29
use Zend\Http\Client;
30
31
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...
32
{
33
    /**
34
     * Create service
35
     *
36
     * @param ServiceLocatorInterface $serviceLocator
37
     * @return YumlController
38
     */
39
    public function createService(ServiceLocatorInterface $serviceLocator)
40
    {
41
        if ($serviceLocator instanceof AbstractPluginManager) {
42
            $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...
43
        }
44
45
        return $this($serviceLocator, YumlController::class);
46
    }
47
48
    /**
49
     * Create an object
50
     *
51
     * @param  ContainerInterface $container
52
     * @param  string             $requestedName
53
     * @param  null|array         $options
54
     * @return YumlController
55
     * @throws ServiceNotFoundException if unable to resolve the service.
56
     * @throws ServiceNotCreatedException if an exception is raised when
57
     *     creating a service.
58
     * @throws ContainerException if any other error occurs
59
     */
60
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
61
    {
62
        $config = $container->get('config');
63
64
        if (! isset($config['zenddevelopertools']['toolbar']['enabled'])
65
            || !$config['zenddevelopertools']['toolbar']['enabled']
66
        ) {
67
            throw new ServiceNotFoundException(
68
                'Service DoctrineORMModule\\Yuml\\YumlController could not be found'
69
            );
70
        }
71
72
        return new YumlController(
73
            new Client('http://yuml.me/diagram/plain/class/', ['timeout' => 30])
74
        );
75
    }
76
}
77