Conditions | 5 |
Paths | 5 |
Total Lines | 30 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
1 | <?php namespace Modules\Core\Internationalisation; |
||
7 | public function save(array $options = array()) |
||
8 | { |
||
9 | $tempTranslations = $this->translations; |
||
|
|||
10 | if ($this->exists) { |
||
11 | if (count($this->getDirty()) > 0) { |
||
12 | // If $this->exists and dirty, parent::save() has to return true. If not, |
||
13 | // an error has occurred. Therefore we shouldn't save the translations. |
||
14 | if (parent::save($options)) { |
||
15 | $this->translations = $tempTranslations; |
||
16 | |||
17 | return $this->saveTranslations(); |
||
18 | } |
||
19 | |||
20 | return false; |
||
21 | } else { |
||
22 | // If $this->exists and not dirty, parent::save() skips saving and returns |
||
23 | // false. So we have to save the translations |
||
24 | $this->translations = $tempTranslations; |
||
25 | |||
26 | return $this->saveTranslations(); |
||
27 | } |
||
28 | } elseif (parent::save($options)) { |
||
29 | // We save the translations only if the instance is saved in the database. |
||
30 | $this->translations = $tempTranslations; |
||
31 | |||
32 | return $this->saveTranslations(); |
||
33 | } |
||
34 | |||
35 | return false; |
||
36 | } |
||
37 | } |
||
38 |
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: