MobileDetectFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 2
1
<?php
2
3
namespace MobileDetectModule\Service;
4
5
use Detection\MobileDetect;
6
use Interop\Container\ContainerInterface;
7
use Zend\Http\PhpEnvironment\Request as HttpRequest;
8
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
9
10
/**
11
 * Creates and builds MobileDetect service.
12
 *
13
 * @author Nikola Posa <[email protected]>
14
 */
15
class MobileDetectFactory
16
{
17
    /**
18
     * @param ContainerInterface $container
19
     * @return MobileDetect
20
     */
21 2
    public function __invoke(ContainerInterface $container)
22
    {
23 2
        if (! $container->has('Request')) {
24 1
            throw new ServiceNotCreatedException('Request object required for creating MobileDetect was not found in the container');
25
        }
26
27
        /* @var $request HttpRequest */
28 1
        $request = $container->get('Request');
29
30 1
        return new MobileDetect(
31 1
            $request->getServer()->toArray(),
32 1
            $request->getServer('HTTP_USER_AGENT')
33
        );
34
    }
35
}
36