Code Duplication    Length = 47-47 lines in 2 locations

src/Surfnet/StepupMiddleware/MiddlewareBundle/Service/VerifiedSecondFactorReminderMailService.php 2 locations

@@ 172-218 (lines=47) @@
169
     * @param $registrationCode
170
     * @return int
171
     */
172
    private function sendReminderWithInstitution(
173
        $locale,
174
        $commonName,
175
        $email,
176
        $requestedAt,
177
        $registrationCode,
178
        $raLocations
179
    ) {
180
        $subject = $this->translator->trans(
181
            'ss.mail.registration_email.subject',
182
            ['%commonName%' => $commonName],
183
            'messages',
184
            $locale
185
        );
186
187
        $emailTemplate = $this->emailTemplateService->findByName(
188
            'second_factor_verification_reminder_with_ra_locations',
189
            $locale,
190
            $this->fallbackLocale
191
        );
192
193
        $parameters = [
194
            'templateString' => $emailTemplate->htmlContent,
195
            'locale' => $locale,
196
            'commonName' => $commonName,
197
            'expirationDate' => $requestedAt,
198
            'registrationCode' => $registrationCode,
199
            'raLocations' => $raLocations,
200
        ];
201
202
        // Rendering file template instead of string
203
        // (https://github.com/symfony/symfony/issues/10865#issuecomment-42438248)
204
        $body = $this->templateEngine->render(
205
            'SurfnetStepupMiddlewareCommandHandlingBundle:SecondFactorMailService:email.html.twig',
206
            $parameters
207
        );
208
209
        /** @var Message $message */
210
        $message = $this->mailer->createMessage();
211
        $message
212
            ->setFrom($this->sender->getEmail(), $this->sender->getName())
213
            ->addTo($email, $commonName)
214
            ->setSubject($subject)
215
            ->setBody($body, 'text/html', 'utf-8');
216
217
        return $this->mailer->send($message);
218
    }
219
220
    private function sendReminderWithRas(
221
        $locale,
@@ 220-266 (lines=47) @@
217
        return $this->mailer->send($message);
218
    }
219
220
    private function sendReminderWithRas(
221
        $locale,
222
        $commonName,
223
        $email,
224
        $requestedAt,
225
        $registrationCode,
226
        array $ras
227
    ) {
228
        $subject = $this->translator->trans(
229
            'ss.mail.registration_email.subject',
230
            ['%commonName%' => $commonName],
231
            'messages',
232
            $locale
233
        );
234
235
        $emailTemplate = $this->emailTemplateService->findByName(
236
            'second_factor_verification_reminder_with_ras',
237
            $locale,
238
            $this->fallbackLocale
239
        );
240
241
        $parameters = [
242
            'templateString' => $emailTemplate->htmlContent,
243
            'locale' => $locale,
244
            'commonName' => $commonName,
245
            'expirationDate' => $requestedAt,
246
            'registrationCode' => $registrationCode,
247
            'ras' => $ras,
248
        ];
249
250
        // Rendering file template instead of string
251
        // (https://github.com/symfony/symfony/issues/10865#issuecomment-42438248)
252
        $body = $this->templateEngine->render(
253
            'SurfnetStepupMiddlewareCommandHandlingBundle:SecondFactorMailService:email.html.twig',
254
            $parameters
255
        );
256
257
        /** @var Message $message */
258
        $message = $this->mailer->createMessage();
259
        $message
260
            ->setFrom($this->sender->getEmail(), $this->sender->getName())
261
            ->addTo($email, $commonName)
262
            ->setSubject($subject)
263
            ->setBody($body, 'text/html', 'utf-8');
264
265
        return $this->mailer->send($message);
266
    }
267
}
268