MobileDetect   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 58.33%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 65
ccs 7
cts 12
cp 0.5833
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 2
A isNotPhone() 0 4 3
A view() 0 4 1
A browserVersion() 0 4 1
A platformVersion() 0 4 1
1
<?php
2
/**
3
 * MobileDetect.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
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\Http;
20
21
use IPub\MobileDetect\Helpers;
22
23
use Jenssegers\Agent;
24
25
/**
26
 * Mobile detect detector service
27
 *
28
 * @package        iPublikuj:MobileDetect!
29
 * @subpackage     common
30
 *
31
 * @author         Adam Kadlec <[email protected]>
32
 */
33 1
final class MobileDetect extends Agent\Agent
34
{
35
	/**
36
	 * @var Helpers\DeviceView
37
	 */
38
	private $deviceView;
39
40
	/**
41
	 * @param Helpers\DeviceView $deviceView
42
	 * @param Http\Request $httpRequest
43
	 */
44
	public function __construct(
45
		Helpers\DeviceView $deviceView,
46
		Http\Request $httpRequest
47
	) {
48
		// Get http headers
49 1
		$httpHeaders = $httpRequest->getHeaders();
50
51 1
		$userAgent = NULL;
52
53
		// If user agent info is set in headers...
54 1
		if (isset($httpHeaders['user-agent'])) {
55
			// ...set user agent details
56
			$userAgent = $httpHeaders['user-agent'];
57
		}
58
59 1
		parent::__construct($httpHeaders, $userAgent);
60
61 1
		$this->deviceView = $deviceView;
62 1
	}
63
64
	/**
65
	 * Check if the device is not mobile phone
66
	 *
67
	 * @return bool
68
	 */
69
	public function isNotPhone() : bool
70
	{
71
		return (($this->isMobile() && $this->isTablet()) || !$this->isMobile());
72
	}
73
74
	/**
75
	 * @return string
76
	 */
77
	public function view() : string
78
	{
79
		return $this->deviceView->getViewType();
80
	}
81
82
	/**
83
	 * @return string
84
	 */
85
	public function browserVersion() : string
86
	{
87
		return (string) $this->version($this->browser());
88
	}
89
90
	/**
91
	 * @return string
92
	 */
93
	public function platformVersion() : string
94
	{
95
		return (string) $this->version($this->platform());
96
	}
97
}
98