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

OnResponseHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 33.33%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 48
ccs 3
cts 9
cp 0.3333
rs 10

3 Methods

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