Conditions | 12 |
Paths | 576 |
Total Lines | 75 |
Code Lines | 42 |
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 |
||
40 | public function process( |
||
41 | $data, |
||
42 | Operation $operation, |
||
43 | array $uriVariables = [], |
||
44 | array $context = [] |
||
45 | ): CStudentPublication { |
||
46 | /** @var CStudentPublication $publication */ |
||
47 | $publication = $data; |
||
48 | |||
49 | $result = $this->persistProcessor->process($publication, $operation, $uriVariables, $context); |
||
50 | |||
51 | $assignment = $publication->getAssignment(); |
||
52 | $courseLink = $publication->getFirstResourceLink(); |
||
53 | $course = $courseLink->getCourse(); |
||
54 | $session = $courseLink->getSession(); |
||
55 | $group = $courseLink->getGroup(); |
||
56 | |||
57 | /** @var User $currentUser */ |
||
58 | $currentUser = $this->security->getUser(); |
||
59 | |||
60 | $isUpdate = $publication->getIid() !== null; |
||
61 | |||
62 | if (!$assignment) { |
||
63 | $assignment = new CStudentPublicationAssignment(); |
||
64 | $assignment->setPublication($publication); |
||
65 | $publication->setAssignment($assignment); |
||
66 | $this->entityManager->persist($assignment); |
||
67 | } |
||
68 | |||
69 | $payload = $context['request']->toArray(); |
||
70 | |||
71 | if (array_key_exists('qualification', $payload)) { |
||
72 | $publication->setQualification((float) $payload['qualification']); |
||
73 | |||
74 | $user = $this->security->getUser(); |
||
75 | if ($user instanceof User) { |
||
76 | $publication->setQualificatorId($user->getId()); |
||
77 | $publication->setDateOfQualification(new \DateTime()); |
||
78 | } |
||
79 | } |
||
80 | |||
81 | if (isset($payload['expiresOn'])) { |
||
82 | $assignment->setExpiresOn(new \DateTime($payload['expiresOn'])); |
||
83 | } |
||
84 | if (isset($payload['endsOn'])) { |
||
85 | $assignment->setEndsOn(new \DateTime($payload['endsOn'])); |
||
86 | } |
||
87 | |||
88 | if (!$isUpdate || $publication->getQualification() > 0) { |
||
89 | $assignment->setEnableQualification(true); |
||
90 | } |
||
91 | |||
92 | if ($publication->addToCalendar) { |
||
93 | $event = $this->saveCalendarEvent($publication, $assignment, $courseLink, $course, $session, $group); |
||
94 | $assignment->setEventCalendarId($event->getIid()); |
||
95 | } elseif (!$isUpdate) { |
||
96 | $assignment->setEventCalendarId(0); |
||
97 | } |
||
98 | |||
99 | if ($assignment->getIid() !== null) { |
||
100 | $publication->setHasProperties($assignment->getIid()); |
||
101 | } |
||
102 | $publication |
||
103 | ->setViewProperties(true) |
||
104 | ->setUser($currentUser); |
||
105 | |||
106 | $this->entityManager->flush(); |
||
107 | |||
108 | $this->saveGradebookConfig($publication, $course, $session); |
||
109 | |||
110 | if (!$isUpdate) { |
||
111 | $this->sendEmailAlertStudentsOnNewHomework($publication, $course, $session); |
||
112 | } |
||
113 | |||
114 | return $result; |
||
115 | } |
||
248 |