Completed
Push — master ( 4d42ec...531169 )
by Sam
04:34 queued 01:51
created

HasPremieredTrait::getRenderedYear()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.2888
c 0
b 0
f 0
cc 5
nc 5
nop 0
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;
0 ignored issues
show
Bug introduced by
The property year does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
32
		// If nothing is available
33
		return Yii::t('Misc', 'Not available');
34
	}
35
}
36