Completed
Push — master ( 35bfed...a5f27e )
by Adam
05:07
created

OnResponseHandler::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 3
Bugs 1 Features 2
Metric Value
c 3
b 1
f 2
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4286
cc 3
eloc 6
nc 3
nop 0
crap 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:FlashMessages!
9
 * @subpackage     Events
10
 * @since          1.0.0
11
 *
12
 * @date           06.02.15
13
 */
14
15
namespace IPub\FlashMessages\Events;
16
17
use IPub;
18
use IPub\FlashMessages;
19
use IPub\FlashMessages\Entities;
20
21
/**
22
 * Flash message storage events
23
 *
24
 * @package        iPublikuj:FlashMessages!
25
 * @subpackage     Events
26
 *
27
 * @author         Adam Kadlec <[email protected]>
28
 */
29
class OnResponseHandler
30 1
{
31
	/**
32
	 * @var FlashMessages\SessionStorage
33
	 */
34
	private $sessionStorage;
35
36
	/**
37
	 * @param FlashMessages\SessionStorage $sessionStorage
38
	 */
39
	public function __construct(FlashMessages\SessionStorage $sessionStorage)
40
	{
41 1
		$this->sessionStorage = $sessionStorage;
42 1
	}
43
44
	/**
45
	 *
46
	 */
47
	public function __invoke()
48
	{
49
		/** @var Entities\IMessage[] $messages */
50 1
		$messages = $this->sessionStorage->get(FlashMessages\SessionStorage::KEY_MESSAGES, []);
51
52 1
		foreach ($messages as $key => $message) {
53 1
			if ($message->isDisplayed()) {
54 1
				unset($messages[$key]);
55 1
			}
56 1
		}
57
58
		// Update messages in session
59 1
		$this->sessionStorage->set(FlashMessages\SessionStorage::KEY_MESSAGES, $messages);
60 1
	}
61
}
62