GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DeviceDetect   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A isTablet() 0 4 1
A isDesktop() 0 4 1
A getCacheManager() 0 4 1
A setOptions() 0 4 1
B __construct() 0 25 5
A isMobile() 0 8 2
A getDeviceDetector() 0 4 1
1
<?php
2
3
namespace CrossKnowledge\DeviceDetectBundle\Services;
4
5
use Symfony\Component\HttpFoundation\RequestStack;
6
use \Doctrine\Common\Cache\CacheProvider;
7
8
class DeviceDetect
9
{
10
    /** @var RequestStack */
11
    protected $requestStack;
12
13
    /** @var \DeviceDetector\DeviceDetector */
14
    protected $deviceDetector;
15
16
    /** @var Cache */
17
    protected $cacheManager;
18
19
    /** @var  [] */
20
    protected $deviceDetectorOptions;
21
22
    public function __construct(RequestStack $stack, CacheProvider $cache, $deviceDetectorOptions)
23
    {
24
        $this->cacheManager = $cache;
0 ignored issues
show
Documentation Bug introduced by
It seems like $cache of type object<Doctrine\Common\Cache\CacheProvider> is incompatible with the declared type object<CrossKnowledge\De...tBundle\Services\Cache> of property $cacheManager.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
25
        $this->requestStack = $stack;
26
        $this->setOptions($deviceDetectorOptions);
27
28
        if (null !== $this->requestStack && $this->requestStack->getCurrentRequest()) {
29
            $userAgent = $this->requestStack->getCurrentRequest()->headers->get('User-Agent');
30
        } else {
31
            $userAgent = '';
32
        }
33
34
        $this->deviceDetector = new \DeviceDetector\DeviceDetector($userAgent);
35
        $this->deviceDetector->setCache($this->getCacheManager());
36
37
        if (!empty($this->deviceDetectorOptions['discard_bot_information'])) {
38
            $this->deviceDetector->discardBotInformation();
39
        }
40
41
        if (!empty($this->deviceDetectorOptions['skip_bot_detection'])) {
42
            $this->deviceDetector->skipBotDetection();
43
        }
44
45
        $this->deviceDetector->parse();
46
    }
47
48
    public function isTablet()
49
    {
50
        return $this->deviceDetector->isTablet();
51
    }
52
53
    public function isMobile()
54
    {
55
        if ($this->deviceDetector->isTablet()) {
56
            return false;
57
        }
58
59
        return $this->deviceDetector->isMobile();
60
    }
61
62
    public function isDesktop()
63
    {
64
        return $this->deviceDetector->isDesktop();
65
    }
66
67
    public function getCacheManager()
68
    {
69
        return $this->cacheManager;
70
    }
71
72
    public function setOptions($deviceDetectorOptions)
73
    {
74
        $this->deviceDetectorOptions = $deviceDetectorOptions;
75
    }
76
77
    public function getDeviceDetector()
78
    {
79
        return $this->deviceDetector;
80
    }
81
}
82