Completed
Push — master ( 659231...788af6 )
by Wanderson
05:06
created

Session   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addAlert() 0 3 1
A showAlerts() 0 6 2
A getAlerts() 0 6 2
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