Completed
Pull Request — master (#494)
by Thomas Mauro
38:48 queued 26:02
created

YumlControllerFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createService() 0 8 3
A __invoke() 0 16 3
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
32
{
33
    /**
34
     * Create service
35
     *
36
     * @param ServiceLocatorInterface $serviceLocator
37
     * @return YumlController
38
     */
39 3
    public function createService(ServiceLocatorInterface $serviceLocator)
40
    {
41 3
        if ($serviceLocator instanceof AbstractPluginManager) {
42 3
            $serviceLocator = $serviceLocator->getServiceLocator() ?: $serviceLocator;
43 3
        }
44
45 3
        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 3
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
0 ignored issues
show
Unused Code introduced by
The parameter $requestedName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
    {
62 3
        $config = $container->get('config');
63
64 3
        if (! isset($config['zenddevelopertools']['toolbar']['enabled'])
65 3
            || !$config['zenddevelopertools']['toolbar']['enabled']
66 3
        ) {
67 2
            throw new ServiceNotFoundException(
68
                'Service DoctrineORMModule\\Yuml\\YumlController could not be found'
69 2
            );
70
        }
71
72 1
        return new YumlController(
73 1
            new Client('http://yuml.me/diagram/plain/class/', ['timeout' => 30])
74 1
        );
75
    }
76
}
77