Passed
Pull Request — master (#26)
by Wanderson
02:55
created

Link::active()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\Utils;
4
5
use Win\Services\Router;
6
7
/**
8
 * Utilitário de Links de Navegação
9
 */
10
abstract class Link
11
{
12
	/**
13
	 * Usado para ativar Links (aceita array)
14
	 *
15
	 * Retorna 'active' se o link for idêntico ao início da URL atual
16
	 * @param string[] $links
17
	 * @return string
18
	 */
19
	public static function active(...$links)
20
	{
21
		$router = Router::instance();
22
		$current = implode('/', $router->segments);
23
24
		foreach ($links as $link) {
25
			if (0 === strpos($router->format($current), $router->format($link))) {
26
				return 'active';
27
			}
28
		}
29
30
		return '';
31
	}
32
}
33