YearColumn::getTypeName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace donatj\MySqlSchema\Columns\Temporal;
4
5
use donatj\MySqlSchema\Columns\Interfaces\RequiredLengthInterface;
6
use donatj\MySqlSchema\Columns\Traits\RequiredLengthTrait;
7
8
class YearColumn extends AbstractTemporalColumn implements RequiredLengthInterface {
9
10
	use RequiredLengthTrait;
11
12
	/**
13
	 * @param string $name
14
	 * @param int    $length 2 or 4
15
	 */
16
	public function __construct( $name, $length = 4 ) {
17
		parent::__construct($name);
18
		$this->setLength($length);
19
	}
20
21
	/**
22
	 * @param int $length 2 or 4
23
	 */
24
	public function setLength( $length ) {
25
		if( $length != 2 && $length != 4 ) {
26
			throw new \InvalidArgumentException("invalid length '{$length}' - year can only be of length 2 or 4");
27
		}
28
29
		$this->length = $length;
30
	}
31
32
33
	/**
34
	 * @return string
35
	 */
36
	public function getTypeName() {
37
		return 'year';
38
	}
39
}
40