Conditions | 5 |
Paths | 5 |
Total Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
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 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: