| Conditions | 6 |
| Paths | 4 |
| Total Lines | 56 |
| Code Lines | 38 |
| 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 |
||
| 25 | protected function processBody() |
||
| 26 | { |
||
| 27 | $resultRecord = $this->xmlRequest->resultRecord; |
||
| 28 | $sourcedId = (string) $resultRecord->sourcedGUID->sourcedId; |
||
| 29 | $resultScore = (float) $resultRecord->result->resultScore->textString; |
||
| 30 | |||
| 31 | if (0 > $resultScore || 1 < $resultScore) { |
||
| 32 | $this->statusInfo |
||
| 33 | ->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_WARNING) |
||
| 34 | ->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_FAILURE); |
||
| 35 | |||
| 36 | return; |
||
| 37 | } |
||
| 38 | |||
| 39 | $sourcedParts = explode(':', $sourcedId); |
||
| 40 | |||
| 41 | $em = Database::getManager(); |
||
| 42 | /** @var GradebookEvaluation $evaluation */ |
||
| 43 | $evaluation = $em->find('ChamiloCoreBundle:GradebookEvaluation', $sourcedParts[0]); |
||
| 44 | /** @var User $user */ |
||
| 45 | $user = $em->find('ChamiloUserBundle:User', $sourcedParts[1]); |
||
| 46 | |||
| 47 | if (empty($evaluation) || empty($user)) { |
||
| 48 | $this->statusInfo |
||
| 49 | ->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_STATUS) |
||
| 50 | ->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_FAILURE); |
||
| 51 | |||
| 52 | return; |
||
| 53 | } |
||
| 54 | |||
| 55 | $score = $evaluation->getMax() * $resultScore; |
||
| 56 | |||
| 57 | $results = Result::load(null, $user->getId(), $evaluation->getId()); |
||
| 58 | |||
| 59 | if (empty($results)) { |
||
| 60 | $result = new Result(); |
||
| 61 | $result->set_evaluation_id($evaluation->getId()); |
||
| 62 | $result->set_user_id($user->getId()); |
||
| 63 | $result->set_score($score); |
||
| 64 | $result->add(); |
||
| 65 | } else { |
||
| 66 | /** @var Result $result */ |
||
| 67 | $result = $results[0]; |
||
| 68 | $result->addResultLog($user->getId(), $evaluation->getId()); |
||
| 69 | $result->set_score($score); |
||
| 70 | $result->save(); |
||
| 71 | } |
||
| 72 | |||
| 73 | $this->statusInfo |
||
| 74 | ->setSeverity(ImsLtiServiceResponseStatus::SEVERITY_STATUS) |
||
| 75 | ->setCodeMajor(ImsLtiServiceResponseStatus::CODEMAJOR_SUCCESS) |
||
| 76 | ->setDescription( |
||
| 77 | sprintf( |
||
| 78 | get_plugin_lang('ScoreForXUserIsYScore', 'ImsLtiPlugin'), |
||
| 79 | $user->getId(), |
||
| 80 | $resultScore |
||
| 81 | ) |
||
| 85 |