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

HasPremieredTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRenderedYear() 0 20 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;
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