YumlControllerFactory::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 9.6333
c 0
b 0
f 0
cc 3
nc 2
nop 3
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineORMModule\Yuml;
6
7
use Interop\Container\ContainerInterface;
8
use Laminas\Http\Client;
9
use Laminas\ServiceManager\AbstractPluginManager;
10
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
11
use Laminas\ServiceManager\FactoryInterface;
12
use Laminas\ServiceManager\ServiceLocatorInterface;
13
use function sprintf;
14
15
class YumlControllerFactory implements FactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Laminas\ServiceManager\FactoryInterface has been deprecated with message: Use Laminas\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...
16
{
17
    /**
18
     * Create service
19
     */
20 3
    public function createService(ServiceLocatorInterface $serviceLocator) : YumlController
21
    {
22 3
        if ($serviceLocator instanceof AbstractPluginManager) {
23 3
            $serviceLocator = $serviceLocator->getServiceLocator() ?: $serviceLocator;
0 ignored issues
show
Deprecated Code introduced by
The method Laminas\ServiceManager\S...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...
24
        }
25
26 3
        return $this($serviceLocator, YumlController::class);
27
    }
28
29
    /**
30
     * Create an object
31
     *
32
     * {@inheritDoc}
33
     */
34 3
    public function __invoke(
35
        ContainerInterface $container,
36
        $requestedName,
37
        ?array $options = null
38
    ) : YumlController {
39 3
        $config = $container->get('config');
40
41 3
        if (! isset($config['laminas-developer-tools']['toolbar']['enabled'])
42 3
            || ! $config['laminas-developer-tools']['toolbar']['enabled']
43
        ) {
44 2
            throw new ServiceNotFoundException(
45 2
                sprintf('Service %s could not be found', YumlController::class)
46
            );
47
        }
48
49 1
        return new YumlController(
50 1
            new Client('https://yuml.me/diagram/plain/class/', ['timeout' => 30])
51
        );
52
    }
53
}
54