MobileDetect   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 59
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A detectDevice() 0 9 1
A getDeviceKind() 0 14 4
A isPhone() 0 4 2
A isComputer() 0 4 1
1
<?php
2
3
namespace PragmaRX\Tracker\Support;
4
5
use Jenssegers\Agent\Agent;
6
7
class MobileDetect extends Agent
8
{
9
    /**
10
     * Detect kind, model and mobility.
11
     *
12
     * @return array
13
     */
14
    public function detectDevice()
15
    {
16
        return [
17
            'kind'      => $this->getDeviceKind(),
18
            'model'     => $this->device(),
19
            'is_mobile' => $this->isMobile(),
20
            'is_robot'  => $this->isRobot(),
21
        ];
22
    }
23
24
    /**
25
     * Get the kind of device.
26
     *
27
     * @internal param $mobile
28
     *
29
     * @return string
30
     */
31
    public function getDeviceKind()
32
    {
33
        $kind = 'unavailable';
34
35
        if ($this->isTablet()) {
36
            $kind = 'Tablet';
37
        } elseif ($this->isPhone()) {
38
            $kind = 'Phone';
39
        } elseif ($this->isComputer()) {
40
            $kind = 'Computer';
41
        }
42
43
        return $kind;
44
    }
45
46
    /**
47
     * Is this a phone?
48
     *
49
     * @return bool
50
     */
51
    public function isPhone($userAgent = null, $httpHeaders = null)
52
    {
53
        return !$this->isTablet() && !$this->isComputer();
54
    }
55
56
    /**
57
     * Is this a computer?
58
     *
59
     * @return bool
60
     */
61
    public function isComputer()
62
    {
63
        return !$this->isMobile();
64
    }
65
}
66