Passed
Branch scrutinizer (391c16)
by Wanderson
01:43
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
	protected $month;
13
14
	const ABBRE_LENGTH = 3;
15
16
	/**
17
	 * @param int|string $month
18
	 * @return static
19
	 */
20
	public static function create($month) {
21
		return new static($month);
22
	}
23
24
	/** @param int|string $month */
25
	public function __construct($month) {
26
		$this->month = (int) $month;
27
	}
28
29
	/** @return string|false */
30
	public function getName() {
31
		return key_exists($this->month, static::$names) ? static::$names[$this->month] : false;
32
	}
33
34
	/**  @return string|false */
35
	public function getNameAbbre() {
36
		$name = $this->getName();
37
		if ($name) {
38
			return strtoupper(substr($name, 0, static::ABBRE_LENGTH));
39
		} else {
40
			return false;
41
		}
42
	}
43
44
}
45