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

OnResponseHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 30%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 50
ccs 3
cts 10
cp 0.3
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A needModifyResponse() 0 4 1
A __invoke() 0 9 3
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