Passed
Push — master ( 9edc41...f34eb1 )
by Adam
03:33
created

MobileDetect::browserVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 1
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * MobileDetect.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec http://www.ipublikuj.eu
8
 * @package        iPublikuj:MobileDetect!
9
 * @subpackage     common
10
 * @since          1.0.0
11
 *
12
 * @date           21.04.14
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\MobileDetect;
18
19
use Nette;
20
use Nette\Http;
21
22
use IPub;
23
use IPub\MobileDetect\Helpers;
24
use IPub\MobileDetect\Templating;
25
26
use Jenssegers\Agent;
27
28
/**
29
 * Mobile detect detector service
30
 *
31
 * @package        iPublikuj:MobileDetect!
32
 * @subpackage     common
33
 *
34
 * @author         Adam Kadlec <[email protected]>
35
 */
36 1
final class MobileDetect extends Agent\Agent
37
{
38
	/**
39
	 * @var Helpers\DeviceView
40
	 */
41
	private $deviceView;
42
43
	/**
44
	 * @param Helpers\DeviceView $deviceView
45
	 * @param Http\Request $httpRequest
46
	 */
47
	public function __construct(
48
		Helpers\DeviceView $deviceView,
49
		Http\Request $httpRequest
50
	) {
51
		// Get http headers
52 1
		$httpHeaders = $httpRequest->getHeaders();
53
54 1
		$userAgent = NULL;
55
56
		// If user agent info is set in headers...
57 1
		if (isset($httpHeaders['user-agent'])) {
58
			// ...set user agent details
59
			$userAgent = $httpHeaders['user-agent'];
60
		}
61
62 1
		parent::__construct($httpHeaders, $userAgent);
63
64 1
		$this->deviceView = $deviceView;
65 1
	}
66
67
	/**
68
	 * Check if the device is not mobile phone
69
	 *
70
	 * @return bool
71
	 */
72
	public function isNotPhone() : bool
73
	{
74
		return (($this->isMobile() && $this->isTablet()) || !$this->isMobile());
75
	}
76
77
	/**
78
	 * @return string
79
	 */
80
	public function view() : string
81
	{
82
		return $this->deviceView->getViewType();
83
	}
84
85
	/**
86
	 * @return float|string
87
	 */
88
	public function browserVersion()
89
	{
90
		return $this->version($this->browser());
91
	}
92
93
	/**
94
	 * @return float|string
95
	 */
96
	public function platformVersion()
97
	{
98
		return $this->version($this->platform());
99
	}
100
}
101