Completed
Push — master ( 9eaf88...69c79a )
by Adam
02:16
created

MobileDetect::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
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 1
cp 0
rs 10
cc 2
eloc 2
nc 2
nop 0
crap 6
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
/**
27
 * Mobile detect detector service
28
 *
29
 * @package        iPublikuj:MobileDetect!
30
 * @subpackage     common
31
 *
32
 * @author         Adam Kadlec <[email protected]>
33
 */
34 1
final class MobileDetect extends \Detection\MobileDetect
35
{
36
	/**
37
	 * @var Helpers\DeviceView
38
	 */
39
	private $deviceView;
40
41
	/**
42
	 * @param Helpers\DeviceView $deviceView
43
	 * @param Http\Request $httpRequest
44
	 */
45
	public function __construct(
46
		Helpers\DeviceView $deviceView,
47
		Http\Request $httpRequest
48
	) {
49
		// Get http headers
50 1
		$httpHeaders = $httpRequest->getHeaders();
51
52 1
		$userAgent = NULL;
53
54
		// If user agent info is set in headers...
55 1
		if (isset($httpHeaders['user-agent'])) {
56
			// ...set user agent details
57
			$userAgent = $httpHeaders['user-agent'];
58
		}
59
60 1
		parent::__construct($httpHeaders, $userAgent);
61
62 1
		$this->deviceView = $deviceView;
63 1
	}
64
65
	/**
66
	 * Check if the device is mobile phone
67
	 *
68
	 * @return bool
69
	 */
70
	public function isPhone() : bool
71
	{
72
		return $this->isMobile() && !$this->isTablet();
73
	}
74
75
	/**
76
	 * Check if the device is not mobile phone
77
	 *
78
	 * @return bool
79
	 */
80
	public function isNotPhone() : bool
81
	{
82
		return (($this->isMobile() && $this->isTablet()) || !$this->isMobile());
83
	}
84
}
85