Code Duplication    Length = 46-47 lines in 4 locations

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

@@ 96-141 (lines=46) @@
93
     * @param string $registrationCode
94
     * @param RegistrationAuthorityCredentials[] $ras
95
     */
96
    public function sendRegistrationEmailWithRas(
97
        $locale,
98
        $commonName,
99
        $email,
100
        $registrationCode,
101
        array $ras
102
    ) {
103
        $subject = $this->translator->trans(
104
            'ss.mail.registration_email.subject',
105
            ['%commonName%' => $commonName],
106
            'messages',
107
            $locale
108
        );
109
110
        $emailTemplate = $this->emailTemplateService->findByName(
111
            'registration_code_with_ras',
112
            $locale,
113
            $this->fallbackLocale
114
        );
115
116
        $parameters = [
117
            'templateString'   => $emailTemplate->htmlContent,
118
            'locale'           => $locale,
119
            'commonName'       => $commonName,
120
            'email'            => $email,
121
            'registrationCode' => $registrationCode,
122
            'ras'              => $ras,
123
        ];
124
125
        // Rendering file template instead of string
126
        // (https://github.com/symfony/symfony/issues/10865#issuecomment-42438248)
127
        $body = $this->templateEngine->render(
128
            'SurfnetStepupMiddlewareCommandHandlingBundle:SecondFactorMailService:email.html.twig',
129
            $parameters
130
        );
131
132
        /** @var Message $message */
133
        $message = $this->mailer->createMessage();
134
        $message
135
            ->setFrom($this->sender->getEmail(), $this->sender->getName())
136
            ->addTo($email, $commonName)
137
            ->setSubject($subject)
138
            ->setBody($body, 'text/html', 'utf-8');
139
140
        $this->mailer->send($message);
141
    }
142
143
    /**
144
     * @param string $locale
@@ 150-195 (lines=46) @@
147
     * @param string $registrationCode
148
     * @param RaLocation[] $raLocations
149
     */
150
    public function sendRegistrationEmailWithRaLocations(
151
        $locale,
152
        $commonName,
153
        $email,
154
        $registrationCode,
155
        array $raLocations
156
    ) {
157
        $subject = $this->translator->trans(
158
            'ss.mail.registration_email.subject',
159
            ['%commonName%' => $commonName],
160
            'messages',
161
            $locale
162
        );
163
164
        $emailTemplate = $this->emailTemplateService->findByName(
165
            'registration_code_with_ra_locations',
166
            $locale,
167
            $this->fallbackLocale
168
        );
169
170
        $parameters = [
171
            'templateString'   => $emailTemplate->htmlContent,
172
            'locale'           => $locale,
173
            'commonName'       => $commonName,
174
            'email'            => $email,
175
            'registrationCode' => $registrationCode,
176
            'raLocations'      => $raLocations,
177
        ];
178
179
        // Rendering file template instead of string
180
        // (https://github.com/symfony/symfony/issues/10865#issuecomment-42438248)
181
        $body = $this->templateEngine->render(
182
            'SurfnetStepupMiddlewareCommandHandlingBundle:SecondFactorMailService:email.html.twig',
183
            $parameters
184
        );
185
186
        /** @var Message $message */
187
        $message = $this->mailer->createMessage();
188
        $message
189
            ->setFrom($this->sender->getEmail(), $this->sender->getName())
190
            ->addTo($email, $commonName)
191
            ->setSubject($subject)
192
            ->setBody($body, 'text/html', 'utf-8');
193
194
        $this->mailer->send($message);
195
    }
196
}
197

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
            'requestedAt' => $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
            'requestedAt' => $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