Passed
Push — master ( 4ef040...cfdc3a )
by Adam
01:59
created

OnResponseHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * OnResponseHandler.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     Events
10
 * @since          1.0.0
11
 *
12
 * @date           23.04.14
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\MobileDetect\Events;
18
19
use Nette\Application;
20
21
use IPub\MobileDetect\Helpers\DeviceView;
22
23
/**
24
 * On response event handler
25
 *
26
 * @package        iPublikuj:MobileDetect!
27
 * @subpackage     Events
28
 *
29
 * @author         Adam Kadlec <[email protected]>
30
 */
31 1
final class OnResponseHandler
32
{
33
	/**
34
	 * @var bool
35
	 */
36
	private $needModifyResponse = FALSE;
37
38
	/**
39
	 * @var DeviceView
40
	 */
41
	private $deviceView;
42
43
	/**
44
	 * @var \Closure
45
	 */
46
	public $modifyResponseClosure;
47
48
	/**
49
	 * @param DeviceView $deviceView
50
	 */
51
	public function __construct(DeviceView $deviceView)
52
	{
53 1
		$this->deviceView = $deviceView;
54 1
	}
55
56
	/**
57
	 * Stores information about modifying response
58
	 *
59
	 * @return void
60
	 */
61
	public function needModifyResponse() : void
62
	{
63
		$this->needModifyResponse = TRUE;
64
	}
65
66
	/**
67
	 * @param Application\Application $application
68
	 *
69
	 * @return void
70
	 */
71
	public function __invoke(Application\Application $application) : void
72
	{
73
		if ($this->needModifyResponse && $this->modifyResponseClosure instanceof \Closure) {
74
			$modifyClosure = $this->modifyResponseClosure;
75
			$modifyClosure($this->deviceView);
76
		}
77
	}
78
}
79