Passed
Push — master ( d021a5...a13070 )
by Sam
03:47 queued 12s
created

HasPremieredTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRenderedYear() 0 19 5
1
<?php
2
3
trait HasPremieredTrait
4
{
5
6
	/**
7
	 * @var string the date the movie premiered
8
	 */
9
	public $premiered;
10
11
12
	/**
13
	 * @return string|int
14
	 */
15
	public function getRenderedYear()
16
	{
17
		// If premiered is available we use the year from that
18
		if ($this->premiered !== '')
19
		{
20
			$premiereDate = DateTime::createFromFormat('Y-m-d', $this->premiered);
21
22
			if ($premiereDate !== false)
23
			{
24
				return $premiereDate->format('Y');
25
			}
26
		}
27
28
		// Year is usually zero or 1601 when it's not available
29
		if ($this->year !== 0 && $this->year !== 1601)
30
			return $this->year;
31
32
		// If nothing is available
33
		return Yii::t('Misc', 'Not available');
34
	}
35
}
36