| Conditions | 13 |
| Paths | 199 |
| Total Lines | 59 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 2 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 126 | public function init() { |
||
| 127 | if ($this->isInitialized()) { |
||
| 128 | throw new \BadMethodCallException('This object from class ' . __CLASS__ . ' is already initialized. It is not possible to init one object twice!'); |
||
| 129 | } |
||
| 130 | |||
| 131 | $this->isInitialized = true; |
||
| 132 | |||
| 133 | $this->userLangs = $this->getUserLangs(); |
||
| 134 | |||
| 135 | // search for language file |
||
| 136 | $this->appliedLang = NULL; |
||
| 137 | foreach ($this->userLangs as $priority => $langcode) { |
||
| 138 | $this->langFilePath = $this->getConfigFilename($langcode); |
||
| 139 | if (file_exists($this->langFilePath)) { |
||
| 140 | $this->appliedLang = $langcode; |
||
| 141 | break; |
||
| 142 | } |
||
| 143 | } |
||
| 144 | if ($this->appliedLang == NULL) { |
||
| 145 | throw new \RuntimeException('No language file was found.'); |
||
| 146 | } |
||
| 147 | |||
| 148 | // search for cache file |
||
| 149 | $this->cacheFilePath = $this->cachePath . '/php_i18n_' . md5_file(__FILE__) . '_' . $this->prefix . '_' . $this->appliedLang . '.cache.php'; |
||
| 150 | |||
| 151 | // whether we need to create a new cache file |
||
| 152 | $outdated = !file_exists($this->cacheFilePath) || |
||
| 153 | filemtime($this->cacheFilePath) < filemtime($this->langFilePath) || // the language config was updated |
||
| 154 | ($this->mergeFallback && filemtime($this->cacheFilePath) < filemtime($this->getConfigFilename($this->fallbackLang))); // the fallback language config was updated |
||
| 155 | |||
| 156 | if ($outdated) { |
||
| 157 | $config = $this->load($this->langFilePath); |
||
| 158 | if ($this->mergeFallback) |
||
| 159 | $config = array_replace_recursive($this->load($this->getConfigFilename($this->fallbackLang)), $config); |
||
| 160 | |||
| 161 | $compiled = "<?php class " . $this->prefix . " {\n" |
||
| 162 | . $this->compile($config) |
||
| 163 | . 'public static function __callStatic($string, $args) {' . "\n" |
||
| 164 | . ' return vsprintf(constant("self::" . $string), $args);' |
||
| 165 | . "\n}\n}\n" |
||
| 166 | . $this->compileFunction(); |
||
| 167 | |||
| 168 | if( ! is_dir($this->cachePath)) |
||
| 169 | mkdir($this->cachePath, 0755, true); |
||
| 170 | |||
| 171 | if (file_put_contents($this->cacheFilePath, $compiled) === FALSE) { |
||
| 172 | throw new \Exception("Could not write cache file to path '" . $this->cacheFilePath . "'. Is it writable?"); |
||
| 173 | } |
||
| 174 | try{ |
||
| 175 | chmod($this->cacheFilePath, 0755); |
||
| 176 | } |
||
| 177 | catch(\Throwable $t){ |
||
| 178 | throw new \Exception("Could chmod cache file '" . $this->cacheFilePath . "'"); |
||
| 179 | } |
||
| 180 | |||
| 181 | |||
| 182 | } |
||
| 183 | |||
| 184 | require_once $this->cacheFilePath; |
||
| 185 | } |
||
| 206 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.