| Conditions | 23 |
| Paths | 4192 |
| Total Lines | 86 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 117 | private function buildDefaultsFromSchemas(): array |
||
| 118 | { |
||
| 119 | $map = []; |
||
| 120 | |||
| 121 | $manager = null; |
||
| 122 | try { |
||
| 123 | if ($this->container->has('chamilo.settings_manager')) { |
||
|
|
|||
| 124 | $manager = $this->container->get('chamilo.settings_manager'); |
||
| 125 | } elseif ($this->container->has('chamilo.core.settings_manager')) { |
||
| 126 | $manager = $this->container->get('chamilo.core.settings_manager'); |
||
| 127 | } elseif ($this->container->has(SettingsManager::class)) { |
||
| 128 | $manager = $this->container->get(SettingsManager::class); |
||
| 129 | } |
||
| 130 | } catch (\Throwable $e) { |
||
| 131 | error_log('[WARN] Unable to retrieve SettingsManager from container: ' . $e->getMessage()); |
||
| 132 | } |
||
| 133 | |||
| 134 | if (!$manager) { |
||
| 135 | error_log('[WARN] SettingsManager not found; defaults map will be empty.'); |
||
| 136 | return $map; |
||
| 137 | } |
||
| 138 | |||
| 139 | try { |
||
| 140 | $schemas = $manager->getSchemas(); |
||
| 141 | } catch (\Throwable $e) { |
||
| 142 | error_log('[WARN] getSchemas() failed on SettingsManager: ' . $e->getMessage()); |
||
| 143 | return $map; |
||
| 144 | } |
||
| 145 | |||
| 146 | foreach (array_keys($schemas) as $serviceIdOrAlias) { |
||
| 147 | $namespace = str_replace('chamilo_core.settings.', '', (string) $serviceIdOrAlias); |
||
| 148 | |||
| 149 | try { |
||
| 150 | $settingsBag = $manager->load($namespace); |
||
| 151 | } catch (\Throwable $e) { |
||
| 152 | error_log(sprintf('[WARN] load("%s") failed: %s', $namespace, $e->getMessage())); |
||
| 153 | continue; |
||
| 154 | } |
||
| 155 | |||
| 156 | $parameters = []; |
||
| 157 | |||
| 158 | try { |
||
| 159 | if (method_exists($settingsBag, 'getParameters')) { |
||
| 160 | $parameters = (array) $settingsBag->getParameters(); |
||
| 161 | } elseif (method_exists($settingsBag, 'all')) { |
||
| 162 | $parameters = (array) $settingsBag->all(); |
||
| 163 | } elseif (method_exists($settingsBag, 'toArray')) { |
||
| 164 | $parameters = (array) $settingsBag->toArray(); |
||
| 165 | } |
||
| 166 | } catch (\Throwable $e) { |
||
| 167 | error_log(sprintf('[WARN] Could not extract parameters for "%s": %s', $namespace, $e->getMessage())); |
||
| 168 | $parameters = []; |
||
| 169 | } |
||
| 170 | |||
| 171 | if (empty($parameters)) { |
||
| 172 | try { |
||
| 173 | $keys = []; |
||
| 174 | if (method_exists($settingsBag, 'keys')) { |
||
| 175 | $keys = (array) $settingsBag->keys(); |
||
| 176 | } elseif (method_exists($settingsBag, 'getIterator')) { |
||
| 177 | $keys = array_keys(iterator_to_array($settingsBag->getIterator())); |
||
| 178 | } |
||
| 179 | foreach ($keys as $k) { |
||
| 180 | try { |
||
| 181 | $parameters[$k] = $settingsBag->get($k); |
||
| 182 | } catch (\Throwable $e) { |
||
| 183 | // ignore |
||
| 184 | } |
||
| 185 | } |
||
| 186 | } catch (\Throwable $e) { |
||
| 187 | error_log(sprintf('[WARN] Parameter keys iteration failed for "%s": %s', $namespace, $e->getMessage())); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 191 | foreach ($parameters as $var => $val) { |
||
| 192 | $var = (string) $var; |
||
| 193 | if ($var === '') { |
||
| 194 | continue; |
||
| 195 | } |
||
| 196 | if (!array_key_exists($var, $map)) { |
||
| 197 | $map[$var] = is_scalar($val) ? (string) $val : (string) json_encode($val); |
||
| 198 | } |
||
| 199 | } |
||
| 200 | } |
||
| 201 | |||
| 202 | return $map; |
||
| 203 | } |
||
| 293 |
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.