Conditions | 21 |
Paths | 650 |
Total Lines | 62 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
90 | public function getSetting($settingName) |
||
91 | { |
||
92 | $plugin = Database::getManager()->getRepository(PluginEntity::class)->findOneBy(['title' => 'Onlyoffice']); |
||
93 | $configuration = $plugin?->getConfigurationsByAccessUrl( |
||
94 | Container::getAccessUrlUtil()->getCurrent() |
||
95 | ); |
||
96 | |||
97 | $value = null; |
||
98 | if (null !== $this->newSettings) { |
||
99 | if (isset($this->newSettings[$settingName])) { |
||
100 | $value = $this->newSettings[$settingName]; |
||
101 | } |
||
102 | |||
103 | if (empty($value)) { |
||
104 | $prefix = $this->plugin->get_name(); |
||
105 | |||
106 | if (substr($settingName, 0, strlen($prefix)) == $prefix) { |
||
107 | $settingNameWithoutPrefix = substr($settingName, strlen($prefix) + 1); |
||
108 | } |
||
109 | |||
110 | if (isset($this->newSettings[$settingNameWithoutPrefix])) { |
||
|
|||
111 | $value = $this->newSettings[$settingNameWithoutPrefix]; |
||
112 | } |
||
113 | } |
||
114 | if ($this->isSettingUrl($value)) { |
||
115 | $value = $this->processUrl($value); |
||
116 | } |
||
117 | if (!empty($value)) { |
||
118 | return $value; |
||
119 | } |
||
120 | } |
||
121 | switch ($settingName) { |
||
122 | case $this->jwtHeader: |
||
123 | $settings = api_get_setting($settingName); |
||
124 | $value = is_array($settings) && array_key_exists($this->plugin->get_name(), $settings) |
||
125 | ? $settings[$this->plugin->get_name()] |
||
126 | : null; |
||
127 | |||
128 | if (empty($value)) { |
||
129 | $value = 'Authorization'; |
||
130 | } |
||
131 | break; |
||
132 | case $this->documentServerInternalUrl: |
||
133 | $settings = api_get_setting($settingName); |
||
134 | $value = is_array($settings) ? ($settings[$this->plugin->get_name()] ?? null) : null; |
||
135 | break; |
||
136 | case $this->useDemoName: |
||
137 | $value = $configuration ? ($configuration[$settingName] ?: null) : null; |
||
138 | break; |
||
139 | case $this->jwtPrefix: |
||
140 | $value = 'Bearer '; |
||
141 | break; |
||
142 | default: |
||
143 | if (!empty($this->plugin) && method_exists($this->plugin, 'get')) { |
||
144 | $value = $this->plugin->get($settingName); |
||
145 | } |
||
146 | } |
||
147 | if (empty($value)) { |
||
148 | $value = api_get_configuration_value($settingName); |
||
149 | } |
||
150 | |||
151 | return $value; |
||
152 | } |
||
210 |