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

OnResponseHandler::__invoke()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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