| Conditions | 39 |
| Paths | 3 |
| Total Lines | 132 |
| Code Lines | 96 |
| 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 |
||
| 217 | public function to_system_encoding(): void |
||
| 218 | { |
||
| 219 | foreach ($this->resources as $type => &$resources) { |
||
| 220 | if (\count($resources) <= 0) { |
||
| 221 | continue; |
||
| 222 | } |
||
| 223 | |||
| 224 | foreach ($resources as &$resource) { |
||
| 225 | switch ($type) { |
||
| 226 | case RESOURCE_ANNOUNCEMENT: |
||
| 227 | case RESOURCE_EVENT: |
||
| 228 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 229 | $resource->content = api_to_system_encoding($resource->content, $this->encoding); |
||
| 230 | break; |
||
| 231 | |||
| 232 | case RESOURCE_DOCUMENT: |
||
| 233 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 234 | $resource->comment = api_to_system_encoding($resource->comment, $this->encoding); |
||
| 235 | break; |
||
| 236 | |||
| 237 | case RESOURCE_FORUM: |
||
| 238 | case RESOURCE_QUIZ: |
||
| 239 | case RESOURCE_FORUMCATEGORY: |
||
| 240 | if (isset($resource->title)) { |
||
| 241 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 242 | } |
||
| 243 | if (isset($resource->description)) { |
||
| 244 | $resource->description = api_to_system_encoding($resource->description, $this->encoding); |
||
| 245 | } |
||
| 246 | if (isset($resource->obj)) { |
||
| 247 | foreach (['cat_title', 'cat_comment', 'title', 'description'] as $f) { |
||
| 248 | if (isset($resource->obj->{$f}) && \is_string($resource->obj->{$f})) { |
||
| 249 | $resource->obj->{$f} = api_to_system_encoding($resource->obj->{$f}, $this->encoding); |
||
| 250 | } |
||
| 251 | } |
||
| 252 | } |
||
| 253 | break; |
||
| 254 | |||
| 255 | case RESOURCE_LINK: |
||
| 256 | case RESOURCE_LINKCATEGORY: |
||
| 257 | case RESOURCE_TEST_CATEGORY: |
||
| 258 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 259 | $resource->description = api_to_system_encoding($resource->description, $this->encoding); |
||
| 260 | break; |
||
| 261 | |||
| 262 | case RESOURCE_FORUMPOST: |
||
| 263 | if (isset($resource->title)) { |
||
| 264 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 265 | } |
||
| 266 | if (isset($resource->text)) { |
||
| 267 | $resource->text = api_to_system_encoding($resource->text, $this->encoding); |
||
| 268 | } |
||
| 269 | if (isset($resource->poster_name)) { |
||
| 270 | $resource->poster_name = api_to_system_encoding($resource->poster_name, $this->encoding); |
||
| 271 | } |
||
| 272 | break; |
||
| 273 | |||
| 274 | case RESOURCE_FORUMTOPIC: |
||
| 275 | if (isset($resource->title)) { |
||
| 276 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 277 | } |
||
| 278 | if (isset($resource->topic_poster_name)) { |
||
| 279 | $resource->topic_poster_name = api_to_system_encoding($resource->topic_poster_name, $this->encoding); |
||
| 280 | } |
||
| 281 | if (isset($resource->title_qualify)) { |
||
| 282 | $resource->title_qualify = api_to_system_encoding($resource->title_qualify, $this->encoding); |
||
| 283 | } |
||
| 284 | break; |
||
| 285 | |||
| 286 | case RESOURCE_GLOSSARY: |
||
| 287 | $resource->name = api_to_system_encoding($resource->name, $this->encoding); |
||
| 288 | $resource->description = api_to_system_encoding($resource->description, $this->encoding); |
||
| 289 | break; |
||
| 290 | |||
| 291 | case RESOURCE_LEARNPATH: |
||
| 292 | $resource->name = api_to_system_encoding($resource->name, $this->encoding); |
||
| 293 | $resource->description = api_to_system_encoding($resource->description, $this->encoding); |
||
| 294 | $resource->content_maker = api_to_system_encoding($resource->content_maker, $this->encoding); |
||
| 295 | $resource->content_license = api_to_system_encoding($resource->content_license, $this->encoding); |
||
| 296 | break; |
||
| 297 | |||
| 298 | case RESOURCE_QUIZQUESTION: |
||
| 299 | $resource->question = api_to_system_encoding($resource->question, $this->encoding); |
||
| 300 | $resource->description = api_to_system_encoding($resource->description, $this->encoding); |
||
| 301 | if (\is_array($resource->answers) && \count($resource->answers) > 0) { |
||
| 302 | foreach ($resource->answers as &$answer) { |
||
| 303 | $answer['answer'] = api_to_system_encoding($answer['answer'], $this->encoding); |
||
| 304 | $answer['comment'] = api_to_system_encoding($answer['comment'], $this->encoding); |
||
| 305 | } |
||
| 306 | } |
||
| 307 | break; |
||
| 308 | |||
| 309 | case RESOURCE_SCORM: |
||
| 310 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 311 | break; |
||
| 312 | |||
| 313 | case RESOURCE_SURVEY: |
||
| 314 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 315 | $resource->subtitle = api_to_system_encoding($resource->subtitle, $this->encoding); |
||
| 316 | $resource->author = api_to_system_encoding($resource->author, $this->encoding); |
||
| 317 | $resource->intro = api_to_system_encoding($resource->intro, $this->encoding); |
||
| 318 | $resource->surveythanks = api_to_system_encoding($resource->surveythanks, $this->encoding); |
||
| 319 | break; |
||
| 320 | |||
| 321 | case RESOURCE_SURVEYQUESTION: |
||
| 322 | $resource->survey_question = api_to_system_encoding($resource->survey_question, $this->encoding); |
||
| 323 | $resource->survey_question_comment = api_to_system_encoding($resource->survey_question_comment, $this->encoding); |
||
| 324 | break; |
||
| 325 | |||
| 326 | case RESOURCE_TOOL_INTRO: |
||
| 327 | $resource->intro_text = api_to_system_encoding($resource->intro_text, $this->encoding); |
||
| 328 | break; |
||
| 329 | |||
| 330 | case RESOURCE_WIKI: |
||
| 331 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 332 | $resource->content = api_to_system_encoding($resource->content, $this->encoding); |
||
| 333 | $resource->reflink = api_to_system_encoding($resource->reflink, $this->encoding); |
||
| 334 | break; |
||
| 335 | |||
| 336 | case RESOURCE_WORK: |
||
| 337 | $resource->url = api_to_system_encoding($resource->url, $this->encoding); |
||
| 338 | $resource->title = api_to_system_encoding($resource->title, $this->encoding); |
||
| 339 | $resource->description = api_to_system_encoding($resource->description, $this->encoding); |
||
| 340 | break; |
||
| 341 | |||
| 342 | default: |
||
| 343 | break; |
||
| 344 | } |
||
| 345 | } |
||
| 346 | } |
||
| 347 | |||
| 348 | $this->encoding = api_get_system_encoding(); |
||
| 349 | } |
||
| 394 |