Passed
Branch tests1.5 (e599bd)
by Wanderson
01:46
created

Month::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\Calendar;
4
5
/**
6
 * Mês
7
 */
8
class Month {
9
10
	/** @var string[] */
11
	public static $names = [1 => 'Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'];
12
13
	/** @var int */
14
	protected $month;
15
16
	const ABBRE_LENGTH = 3;
17
18
	/**
19
	 * @param int|string $month
20
	 * @return static
21
	 */
22
	public static function create($month) {
23
		return new static($month);
24
	}
25
26
	/** @param int|string $month */
27
	public function __construct($month) {
28
		$this->month = (int) $month;
29
	}
30
31
	/** @return string|false */
32
	public function getName() {
33
		return key_exists($this->month, static::$names) ? static::$names[$this->month] : false;
34
	}
35
36
	/**  @return string|false */
37
	public function getNameAbbre() {
38
		$name = $this->getName();
39
		if ($name) {
40
			return strtoupper(substr($name, 0, static::ABBRE_LENGTH));
41
		} else {
42
			return false;
43
		}
44
	}
45
46
}
47