Conditions | 5 |
Paths | 6 |
Total Lines | 58 |
Code Lines | 35 |
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 |
||
131 | private function processUsers( |
||
132 | array $users, |
||
133 | int $defaultSenderId, |
||
134 | SymfonyStyle $io, |
||
135 | bool $debug |
||
136 | ): string { |
||
137 | |||
138 | $administrator = [ |
||
139 | 'completeName' => $this->settingsManager->getSetting('admin.administrator_name'), |
||
140 | 'email' => $this->settingsManager->getSetting('admin.administrator_email'), |
||
141 | ]; |
||
142 | |||
143 | $rootweb = $this->settingsManager->getSetting('platform.institution_url'); |
||
144 | $link = $rootweb . '/main/admin/user_list_consent.php'; |
||
145 | $subject = $this->translator->trans('A user is waiting for an action about his/her personal data request'); |
||
146 | $email = $this->settingsManager->getSetting('profile.data_protection_officer_email'); |
||
147 | $message = ''; |
||
148 | |||
149 | foreach ($users as $user) { |
||
150 | $userId = $user['id']; |
||
151 | $userInfo = $this->connection->fetchAssociative("SELECT * FROM user WHERE id = ?", [$userId]); |
||
152 | $userInfo['complete_name'] = $userInfo['firstname'] . ' ' . $userInfo['lastname']; |
||
153 | $userInfo['complete_name_with_username'] = $userInfo['complete_name'].' ('.$userInfo['username'].')'; |
||
154 | |||
155 | if (!$userInfo) { |
||
156 | continue; |
||
157 | } |
||
158 | |||
159 | $content = $this->translator->trans( |
||
160 | 'The user %name% is waiting for an action about his/her personal data request. To manage personal data requests you can follow this link: %link%', |
||
161 | ['%name%' => $userInfo['complete_name'], '%link%' => $link] |
||
162 | ); |
||
163 | |||
164 | if ($email) { |
||
165 | $emailMessage = (new TemplatedEmail()) |
||
166 | ->from($administrator['email']) |
||
167 | ->to($email) |
||
168 | ->subject($subject) |
||
169 | ->html($content); |
||
170 | |||
171 | $this->mailer->send($emailMessage); |
||
172 | } else { |
||
173 | MessageManager::sendMessageToAllAdminUsers($defaultSenderId, $subject, $content); |
||
174 | } |
||
175 | |||
176 | $date = (new DateTime($user['updated_at']))->format('Y-m-d H:i:s'); |
||
177 | $message .= sprintf( |
||
178 | "User %s is waiting for an action since %s \n", |
||
179 | $userInfo['complete_name_with_username'], |
||
180 | $date |
||
181 | ); |
||
182 | |||
183 | if ($debug) { |
||
184 | $io->note("Processed user {$userInfo['complete_name']} with ID: {$userId}"); |
||
185 | } |
||
186 | } |
||
187 | |||
188 | return $message; |
||
189 | } |
||
191 |