| Conditions | 28 |
| Paths | 26 |
| Total Lines | 92 |
| Code Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 193 | public function to_system_encoding() |
||
| 194 | { |
||
| 195 | if (api_equal_encodings($this->encoding, api_get_system_encoding())) { |
||
| 196 | return; |
||
| 197 | } |
||
| 198 | |||
| 199 | foreach ($this->resources as $type => &$resources) { |
||
| 200 | if (count($resources) > 0) { |
||
| 201 | foreach ($resources as &$resource) { |
||
| 202 | switch ($type) { |
||
| 203 | case RESOURCE_ANNOUNCEMENT: |
||
| 204 | case RESOURCE_EVENT: |
||
| 205 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 206 | $resource->content = api_to_system_encoding($resource->content, $this->encoding); |
||
| 207 | break; |
||
| 208 | case RESOURCE_DOCUMENT: |
||
| 209 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 210 | $resource->comment = api_to_system_encoding($resource->comment, $this->encoding); |
||
| 211 | break; |
||
| 212 | case RESOURCE_FORUM: |
||
| 213 | case RESOURCE_QUIZ: |
||
| 214 | case RESOURCE_FORUMCATEGORY: |
||
| 215 | case RESOURCE_LINK: |
||
| 216 | case RESOURCE_LINKCATEGORY: |
||
| 217 | case RESOURCE_TEST_CATEGORY: |
||
| 218 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 219 | $resource->description = api_to_system_encoding($resource->description, $this->encoding); |
||
| 220 | break; |
||
| 221 | case RESOURCE_FORUMPOST: |
||
| 222 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 223 | $resource->text = api_to_system_encoding($resource->text, $this->encoding); |
||
| 224 | $resource->poster_name = api_to_system_encoding($resource->poster_name, $this->encoding); |
||
| 225 | break; |
||
| 226 | case RESOURCE_FORUMTOPIC: |
||
| 227 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 228 | $resource->topic_poster_name = api_to_system_encoding($resource->topic_poster_name, $this->encoding); |
||
| 229 | $resource->title_qualify = api_to_system_encoding($resource->title_qualify, $this->encoding); |
||
| 230 | break; |
||
| 231 | case RESOURCE_GLOSSARY: |
||
| 232 | $resource->name = api_to_system_encoding($resource->name, $this->encoding); |
||
| 233 | $resource->description = api_to_system_encoding($resource->description, $this->encoding); |
||
| 234 | break; |
||
| 235 | case RESOURCE_LEARNPATH: |
||
| 236 | $resource->name = api_to_system_encoding($resource->name, $this->encoding); |
||
| 237 | $resource->description = api_to_system_encoding($resource->description, $this->encoding); |
||
| 238 | $resource->content_maker = api_to_system_encoding($resource->content_maker, $this->encoding); |
||
| 239 | $resource->content_license = api_to_system_encoding($resource->content_license, $this->encoding); |
||
| 240 | break; |
||
| 241 | case RESOURCE_QUIZQUESTION: |
||
| 242 | $resource->question = api_to_system_encoding($resource->question, $this->encoding); |
||
| 243 | $resource->description = api_to_system_encoding($resource->description, $this->encoding); |
||
| 244 | if (is_array($resource->answers) && count($resource->answers) > 0) { |
||
| 245 | foreach ($resource->answers as &$answer) { |
||
| 246 | $answer['answer'] = api_to_system_encoding($answer['answer'], $this->encoding); |
||
| 247 | $answer['comment'] = api_to_system_encoding($answer['comment'], $this->encoding); |
||
| 248 | } |
||
| 249 | } |
||
| 250 | break; |
||
| 251 | case RESOURCE_SCORM: |
||
| 252 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 253 | break; |
||
| 254 | case RESOURCE_SURVEY: |
||
| 255 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 256 | $resource->subtitle = api_to_system_encoding($resource->subtitle, $this->encoding); |
||
| 257 | $resource->author = api_to_system_encoding($resource->author, $this->encoding); |
||
| 258 | $resource->intro = api_to_system_encoding($resource->intro, $this->encoding); |
||
| 259 | $resource->surveythanks = api_to_system_encoding($resource->surveythanks, $this->encoding); |
||
| 260 | break; |
||
| 261 | case RESOURCE_SURVEYQUESTION: |
||
| 262 | $resource->survey_question = api_to_system_encoding($resource->survey_question, $this->encoding); |
||
| 263 | $resource->survey_question_comment = api_to_system_encoding($resource->survey_question_comment, $this->encoding); |
||
| 264 | break; |
||
| 265 | case RESOURCE_TOOL_INTRO: |
||
| 266 | $resource->intro_text = api_to_system_encoding($resource->intro_text, $this->encoding); |
||
| 267 | break; |
||
| 268 | case RESOURCE_WIKI: |
||
| 269 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 270 | $resource->content = api_to_system_encoding($resource->content, $this->encoding); |
||
| 271 | $resource->reflink = api_to_system_encoding($resource->reflink, $this->encoding); |
||
| 272 | break; |
||
| 273 | case RESOURCE_WORK: |
||
| 274 | $resource->url = api_to_system_encoding($resource->url, $this->encoding); |
||
| 275 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 276 | $resource->description = api_to_system_encoding($resource->description, $this->encoding); |
||
| 277 | break; |
||
| 278 | default: |
||
| 279 | break; |
||
| 280 | } |
||
| 281 | } |
||
| 282 | } |
||
| 283 | } |
||
| 284 | $this->encoding = api_get_system_encoding(); |
||
| 285 | } |
||
| 340 |