Passed
Branch v1.4.0 (c6dc92)
by Wanderson
01:17
created

View::getDynamicTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\Mvc;
4
5
use Win\Html\Seo\Title;
6
7
/**
8
 * View
9
 *
10
 * Responsável por criar o visual da página
11
 */
12
class View extends Block
13
{
14
	public static $dir = '/app/views';
15
16
	/**
17
	 * Cria uma View com base no arquivo escolhido
18
	 * @param string $file arquivo da View
19
	 * @param mixed[] $data Variáveis
20
	 */
21
	public function __construct($file, $data = [])
22
	{
23
		parent::__construct($file, $data);
24
	}
25
26
	/**
27
	 * Executa o ErrorPage caso a view não exista
28
	 * @throws HttpException
29
	 */
30
	public function validate()
31
	{
32
		if (!$this->exists()) {
33
			throw new HttpException(404);
34
		}
35
	}
36
37
	/**
38
	 * Adiciona um array de variáveis para usar na View
39
	 * @param mixed[] $data
40
	 */
41
	public function mergeData(array $data)
42
	{
43
		$this->data = array_merge($this->data, $data);
44
	}
45
46
	/** @return string */
47
	public function getTitle()
48
	{
49
		if (empty($this->getData('title'))) {
50
			$this->addData('title', $this->getDynamicTitle());
51
		}
52
53
		return $this->getData('title');
54
	}
55
56
	/** @return string */
57
	private function getDynamicTitle()
58
	{
59
		return Title::otimize(ucwords(str_replace('-', ' ', $this->app->getPage())));
60
	}
61
}
62