Code Duplication    Length = 46-46 lines in 2 locations

src/Surfnet/StepupMiddleware/CommandHandlingBundle/Identity/Service/SecondFactorMailService.php 2 locations

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