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

Month   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getName() 0 2 2
A getNameAbbre() 0 6 2
A create() 0 2 1
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