Completed
Push — master ( c7b167...faaa80 )
by Wanderson
02:08
created

Session   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 41
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addAlert() 0 3 1
A showAlerts() 0 6 2
A getAlerts() 0 6 2
A hasAlert() 0 3 1
1
<?php
2
3
namespace Win\Alert;
4
5
/**
6
 * Armazena e exibe Alertas
7
 */
8
class Session {
9
10
	/**
11
	 * Adicina o alerta no container
12
	 * @param Alert $alert
13
	 */
14
	public static function addAlert(Alert $alert) {
15
		$_SESSION['alerts'][] = $alert;
16
	}
17
18
	/**
19
	 * Mostra todos os alertas criados
20
	 * E remove os alertas da SESSAO
21
	 */
22
	public static function showAlerts() {
23
		foreach (static::getAlerts() as $alert) {
24
			$alert->load();
25
		}
26
		unset($_SESSION['alerts']);
27
	}
28
29
	/**
30
	 * Retorna array de alertas da Sessao
31
	 * @return Alert[]
32
	 */
33
	public static function getAlerts() {
34
		if (!isset($_SESSION['alerts'])) {
35
			$_SESSION['alerts'] = [];
36
		}
37
		return array_unique($_SESSION['alerts']);
38
	}
39
40
	/**
41
	 * Retorna TRUE se possui algum alert
42
	 * @return boolean
43
	 */
44
	public static function hasAlert() {
45
		return !count(static::getAlerts());
46
	}
47
48
}
49