Passed
Branch scrutinizer (391c16)
by Wanderson
01:43
created

Alert::isGroup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\Alert;
4
5
use Win\Mvc\Block;
6
7
/**
8
 * Alertas
9
 * São mensagens armazenadas na sessão e exibidas ao usuário
10
 * @var string TYPE
11
 */
12
abstract class Alert {
13
14
	public $type;
15
	public $group;
16
	public $message;
17
	protected static $file = 'layout/html/alert';
18
19
	/**
20
	 * Cria um novo alerta
21
	 * @param string $message
22
	 */
23
	public function __construct($message, $group = null) {
24
		$this->message = $message;
25
		$this->type = static::TYPE;
0 ignored issues
show
Bug introduced by
The constant Win\Alert\Alert::TYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
26
		$this->group = $group;
27
		Session::addAlert($this);
28
	}
29
30
	/** @return string */
31
	public function __toString() {
32
		return $this->message;
33
	}
34
35
	/**
36
	 * Exibe o conteúdo HTML do alerta
37
	 */
38
	public function load() {
39
		$block = new Block(static::$file, ['alert' => $this]);
40
		$block->load();
41
	}
42
43
	/**
44
	 * Cria um alerta de erro ou sucesso, dependendo dos parâmetros
45
	 * Possibilitando criar um "AlertError" ou "AlertSuccess" em um único método
46
	 * @param string|null $error
47
	 * @param string $success
48
	 * @return Alert
49
	 */
50
	public static function create($error, $success, $group = null) {
51
		if (!is_null($error)) {
52
			return new AlertError($error, $group);
53
		} else {
54
			return new AlertSuccess($success, $group);
55
		}
56
	}
57
58
	/**
59
	 * @param string $group
60
	 * @return boolean
61
	 */
62
	public function isGroup($group) {
63
		return ($group == '' || $group == $this->group);
64
	}
65
66
	/**
67
	 * @param string $type
68
	 * @return boolean
69
	 */
70
	public function isType($type = '') {
71
		return ($type == '' || $type == $this->type);
72
	}
73
74
}
75