Passed
Branch v1.9.0 (cca816)
by Wanderson
07:22
created

Seo   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A title() 0 6 1
A keywords() 0 6 1
A description() 0 6 2
1
<?php
2
3
namespace Win\Utils;
4
5
use Win\Utils\Str;
6
7
/**
8
 * Utilitário de Seo
9
 */
10
abstract class Seo
11
{
12
	public static $titlePrefix = '';
13
	public static $titleSuffix = '';
14
15
	/**
16
	 * Keywords padrão.
17
	 * Usadas quando as keywords informadas não tenha o tamanho suficiente
18
	 * @var string[]
19
	 */
20
	public static $keywords = [];
21
22
	/**
23
	 * Descrição padrão.
24
	 * Usadas quando a descrição informada não tenha o tamanho suficiente
25
	 * @var string
26
	 */
27
	public static $description = '';
28
29
	/**
30
	 * Retorna o título com o nome da aplicação no final
31
	 * Mantendo o máximo de caracteres
32
	 * @param string $title
33
	 * @param string $maxLength
34
	 * @return string
35
	 */
36
	public static function title($title, $maxLength = 70)
37
	{
38
		$staticLength = Str::length(static::$titlePrefix) + Str::length(static::$titleSuffix);
39
		$maxLength = $maxLength - $staticLength;
40
41
		return static::$titlePrefix . Str::truncate($title, $maxLength) . static::$titleSuffix;
42
	}
43
44
45
	/**
46
	 * Retorna uma string em minúscula, separada por virgula
47
	 * @param string[] $keys
48
	 * @param int $maxLength
49
	 * @return string
50
	 */
51
	public static function keywords($keys, $maxLength = 100)
52
	{
53
		$keys = array_merge($keys, static::$keywords);
54
		$keys = Str::truncate(implode(', ', array_filter($keys)), $maxLength);
55
56
		return Str::lower(str_replace([',...', '...'], '', $keys));
57
	}
58
59
	/**
60
	 * Retorna a 'description' com tamanho ideal
61
	 * @param string $description
62
	 * @param int $maxLength
63
	 * @return string
64
	 */
65
	public static function description($description, $maxLength = 150)
66
	{
67
		if (Str::length($description) > 0) {
68
			return Str::truncate($description, $maxLength);
69
		} else {
70
			return static::$description;
71
		}
72
	}
73
}
74