Conditions | 7 |
Paths | 8 |
Total Lines | 67 |
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 |
||
30 | public function __invoke(): Response |
||
31 | { |
||
32 | parent::__invoke(); |
||
33 | |||
34 | $tokenIsValid = Security::check_token('get', null, 'exercisefocused'); |
||
35 | |||
36 | if (!$tokenIsValid) { |
||
37 | throw new Exception('token invalid'); |
||
38 | } |
||
39 | |||
40 | $action = $this->request->query->get('action'); |
||
41 | $levelId = $this->request->query->getInt('level_id'); |
||
42 | |||
43 | $exeId = (int) ChamiloSession::read('exe_id'); |
||
44 | |||
45 | if (!in_array($action, self::VALID_ACTIONS)) { |
||
46 | throw new Exception('action invalid'); |
||
47 | } |
||
48 | |||
49 | $trackingExercise = $this->em->find(TrackEExercises::class, $exeId); |
||
50 | |||
51 | if (!$trackingExercise) { |
||
52 | throw new Exception('no exercise attempt'); |
||
53 | } |
||
54 | |||
55 | $objExercise = new Exercise($trackingExercise->getCId()); |
||
56 | $objExercise->read($trackingExercise->getExeExoId()); |
||
57 | |||
58 | $level = 0; |
||
59 | |||
60 | if (ONE_PER_PAGE == $objExercise->selectType()) { |
||
61 | $question = $this->em->find(CQuizQuestion::class, $levelId); |
||
62 | |||
63 | if (!$question) { |
||
64 | throw new Exception('Invalid level'); |
||
65 | } |
||
66 | |||
67 | $level = $question->getIid(); |
||
68 | } |
||
69 | |||
70 | $log = new Log(); |
||
71 | $log |
||
72 | ->setAction($action) |
||
73 | ->setExe($trackingExercise) |
||
74 | ->setLevel($level); |
||
75 | |||
76 | $this->em->persist($log); |
||
77 | $this->em->flush(); |
||
78 | |||
79 | $remainingOutfocused = -1; |
||
80 | |||
81 | if ('true' === $this->plugin->get(ExerciseFocusedPlugin::SETTING_ENABLE_OUTFOCUSED_LIMIT)) { |
||
82 | $countOutfocused = $this->logRepository->countByActionInExe($trackingExercise, Log::TYPE_OUTFOCUSED); |
||
83 | |||
84 | $remainingOutfocused = (int) $this->plugin->get(ExerciseFocusedPlugin::SETTING_OUTFOCUSED_LIMIT) - $countOutfocused; |
||
85 | } |
||
86 | |||
87 | $exercise = new Exercise(api_get_course_int_id()); |
||
88 | $exercise->read($trackingExercise->getExeExoId()); |
||
89 | |||
90 | $json = [ |
||
91 | 'sec_token' => Security::get_token('exercisefocused'), |
||
92 | 'type' => (int) $exercise->selectType(), |
||
93 | 'remainingOutfocused' => $remainingOutfocused, |
||
94 | ]; |
||
95 | |||
96 | return JsonResponse::create($json); |
||
97 | } |
||
99 |