| Conditions | 5 |
| Paths | 7 |
| Total Lines | 40 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function getStr($index) { |
||
| 22 | |||
| 23 | if (!isset($this->language)) { |
||
| 24 | |||
| 25 | throw BotException("Language not set"); |
||
| 26 | |||
| 27 | } |
||
| 28 | |||
| 29 | // If the language of the user is already set in the array containing localizated strings |
||
| 30 | if (!isset($this->local[$this->language])) { |
||
| 31 | |||
| 32 | // Is the bot using webhook? |
||
| 33 | if (isset($this->webhook)) { |
||
| 34 | |||
| 35 | // Load only the user language in array |
||
| 36 | $this->loadSingleLanguage($this->localization_dir); |
||
| 37 | |||
| 38 | } else { |
||
| 39 | |||
| 40 | // Load all localization files |
||
| 41 | $this->loadLocalization($this->localization_dir); |
||
| 42 | |||
| 43 | } |
||
| 44 | |||
| 45 | } |
||
| 46 | |||
| 47 | |||
| 48 | |||
| 49 | // Check if the string needed exists |
||
| 50 | if (isset($this->local[$this->language][$index])) { |
||
| 51 | |||
| 52 | // If yes, return it |
||
| 53 | return $this->local[$this->language][$index]; |
||
| 54 | |||
| 55 | } |
||
| 56 | |||
| 57 | // Throw an error |
||
| 58 | throw BotException("$index is not set for {$this->language}"); |
||
| 59 | |||
| 60 | } |
||
| 61 | |||
| 64 |
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: