Completed
Push — master ( c4d057...a4831f )
by ARCANEDEV
07:52
created

DeviceDetector::isPhone()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
cc 2
eloc 2
nc 2
nop 0
crap 6
1
<?php namespace Arcanedev\LaravelTracker\Detectors;
2
3
use Arcanedev\LaravelTracker\Contracts\Detectors\DeviceDetector as DeviceDetectorContract;
4
5
/**
6
 * Class     DeviceDetector
7
 *
8
 * @package  Arcanedev\LaravelTracker\Detectors
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class DeviceDetector implements DeviceDetectorContract
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Properties
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /** @var \Jenssegers\Agent\Agent */
18
    protected $agent;
19
20
    /* ------------------------------------------------------------------------------------------------
21
     |  Constructor
22
     | ------------------------------------------------------------------------------------------------
23
     */
24
    /**
25
     * DeviceDetector constructor.
26
     *
27
     * @param  \Jenssegers\Agent\Agent  $agent
28
     */
29
    public function __construct($agent)
30
    {
31
        $this->agent = $agent;
32
    }
33
34
    /* ------------------------------------------------------------------------------------------------
35
     |  Main Functions
36
     | ------------------------------------------------------------------------------------------------
37
     */
38
    /**
39
     * Detect kind, model and mobility.
40
     *
41
     * @return array
42
     */
43
    public function detect()
44
    {
45
        return [
46
            'kind'      => $this->getDeviceKind(),
47
            'model'     => $this->agent->device() ?: '',
48
            'is_mobile' => $this->agent->isMobile(),
49
        ];
50
    }
51
52
    /**
53
     * Get the kind of device.
54
     *
55
     * @return string
56
     */
57
    public function getDeviceKind()
58
    {
59
        if ($this->isTablet())   return 'Tablet';
60
        if ($this->isPhone())    return 'Phone';
61
        if ($this->isComputer()) return 'Computer';
62
63
        return 'unavailable';
64
    }
65
66
    /**
67
     * Is this a tablet?
68
     *
69
     * @return bool
70
     */
71
    public function isTablet()
72
    {
73
        return $this->agent->isTablet();
74
    }
75
76
    /**
77
     * Is this a computer?
78
     *
79
     * @return bool
80
     */
81
    public function isComputer()
82
    {
83
        return ! $this->agent->isMobile();
84
    }
85
86
    /**
87
     * Is this a phone?
88
     *
89
     * @return bool
90
     */
91
    public function isPhone()
92
    {
93
        return ! ($this->isTablet() || $this->isComputer());
94
    }
95
}
96