| Conditions | 20 |
| Paths | 650 |
| Total Lines | 58 |
| Code Lines | 40 |
| 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 |
||
| 83 | public function getSetting($settingName) |
||
| 84 | { |
||
| 85 | $value = null; |
||
| 86 | if (null !== $this->newSettings) { |
||
| 87 | if (isset($this->newSettings[$settingName])) { |
||
| 88 | $value = $this->newSettings[$settingName]; |
||
| 89 | } |
||
| 90 | |||
| 91 | if (empty($value)) { |
||
| 92 | $prefix = $this->plugin->getPluginName(); |
||
| 93 | |||
| 94 | if (substr($settingName, 0, strlen($prefix)) == $prefix) { |
||
| 95 | $settingNameWithoutPrefix = substr($settingName, strlen($prefix) + 1); |
||
| 96 | } |
||
| 97 | |||
| 98 | if (isset($this->newSettings[$settingNameWithoutPrefix])) { |
||
|
|
|||
| 99 | $value = $this->newSettings[$settingNameWithoutPrefix]; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | if ($this->isSettingUrl($value)) { |
||
| 103 | $value = $this->processUrl($value); |
||
| 104 | } |
||
| 105 | if (!empty($value)) { |
||
| 106 | return $value; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | switch ($settingName) { |
||
| 110 | case $this->jwtHeader: |
||
| 111 | $settings = api_get_setting($settingName); |
||
| 112 | $value = is_array($settings) && array_key_exists($this->plugin->getPluginName(), $settings) |
||
| 113 | ? $settings[$this->plugin->getPluginName()] |
||
| 114 | : null; |
||
| 115 | |||
| 116 | if (empty($value)) { |
||
| 117 | $value = 'Authorization'; |
||
| 118 | } |
||
| 119 | break; |
||
| 120 | case $this->documentServerInternalUrl: |
||
| 121 | $settings = api_get_setting($settingName); |
||
| 122 | $value = is_array($settings) ? ($settings[$this->plugin->getPluginName()] ?? null) : null; |
||
| 123 | break; |
||
| 124 | case $this->useDemoName: |
||
| 125 | $settings = api_get_setting($settingName); |
||
| 126 | $value = is_array($settings) ? ($settings[0] ?? null) : null; |
||
| 127 | break; |
||
| 128 | case $this->jwtPrefix: |
||
| 129 | $value = 'Bearer '; |
||
| 130 | break; |
||
| 131 | default: |
||
| 132 | if (!empty($this->plugin) && method_exists($this->plugin, 'get')) { |
||
| 133 | $value = $this->plugin->get($settingName); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | if (empty($value)) { |
||
| 137 | $value = api_get_configuration_value($settingName); |
||
| 138 | } |
||
| 139 | |||
| 140 | return $value; |
||
| 141 | } |
||
| 178 |