Code Duplication    Length = 48-48 lines in 2 locations

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

@@ 111-158 (lines=48) @@
108
     * @param SecondFactorType $secondFactorType
109
     * @param SecondFactorIdentifier $secondFactorIdentifier
110
     */
111
    public function sendVettedSecondFactorRevokedByRaEmail(
112
        Locale $locale,
113
        CommonName $commonName,
114
        Email $email,
115
        SecondFactorType $secondFactorType,
116
        SecondFactorIdentifier $secondFactorIdentifier
117
    ) {
118
        $subject = $this->translator->trans(
119
            'mw.mail.second_factor_revoked.subject',
120
            [
121
                '%tokenType%' => $secondFactorType
122
            ],
123
            'messages',
124
            $locale->getLocale()
125
        );
126
127
        $emailTemplate = $this->emailTemplateService->findByName(
128
            'second_factor_revoked',
129
            $locale->getLocale(),
130
            $this->fallbackLocale
131
        );
132
        $parameters = [
133
            'isRevokedByRa'   => true,
134
            'templateString'  => $emailTemplate->htmlContent,
135
            'commonName'      => $commonName->getCommonName(),
136
            'tokenType'       => $secondFactorType->getSecondFactorType(),
137
            'tokenIdentifier' => $secondFactorIdentifier->getValue(),
138
            'selfServiceUrl'  => $this->selfServiceUrl,
139
            'locale'          => $locale->getLocale(),
140
        ];
141
142
        // Rendering file template instead of string
143
        // (https://github.com/symfony/symfony/issues/10865#issuecomment-42438248)
144
        $body = $this->templateEngine->render(
145
            'SurfnetStepupMiddlewareCommandHandlingBundle:SecondFactorMailService:email.html.twig',
146
            $parameters
147
        );
148
149
        /** @var Message $message */
150
        $message = $this->mailer->createMessage();
151
        $message
152
            ->setFrom($this->sender->getEmail(), $this->sender->getName())
153
            ->addTo($email->getEmail(), $commonName->getCommonName())
154
            ->setSubject($subject)
155
            ->setBody($body, 'text/html', 'utf-8');
156
157
        $this->mailer->send($message);
158
    }
159
160
    /**
161
     * @param Locale $locale
@@ 167-214 (lines=48) @@
164
     * @param SecondFactorType $secondFactorType
165
     * @param SecondFactorIdentifier $secondFactorIdentifier
166
     */
167
    public function sendVettedSecondFactorRevokedByRegistrantEmail(
168
        Locale $locale,
169
        CommonName $commonName,
170
        Email $email,
171
        SecondFactorType $secondFactorType,
172
        SecondFactorIdentifier $secondFactorIdentifier
173
    ) {
174
        $subject = $this->translator->trans(
175
            'mw.mail.second_factor_revoked.subject',
176
            [
177
                '%tokenType%' => $secondFactorType
178
            ],
179
            'messages',
180
            $locale->getLocale()
181
        );
182
183
        $emailTemplate = $this->emailTemplateService->findByName(
184
            'second_factor_revoked',
185
            $locale->getLocale(),
186
            $this->fallbackLocale
187
        );
188
        $parameters = [
189
            'isRevokedByRa'   => false,
190
            'templateString'  => $emailTemplate->htmlContent,
191
            'commonName'      => $commonName->getCommonName(),
192
            'tokenType'       => $secondFactorType->getSecondFactorType(),
193
            'tokenIdentifier' => $secondFactorIdentifier->getValue(),
194
            'selfServiceUrl'  => $this->selfServiceUrl,
195
            'locale'          => $locale->getLocale(),
196
        ];
197
198
        // Rendering file template instead of string
199
        // (https://github.com/symfony/symfony/issues/10865#issuecomment-42438248)
200
        $body = $this->templateEngine->render(
201
            'SurfnetStepupMiddlewareCommandHandlingBundle:SecondFactorMailService:email.html.twig',
202
            $parameters
203
        );
204
205
        /** @var Message $message */
206
        $message = $this->mailer->createMessage();
207
        $message
208
            ->setFrom($this->sender->getEmail(), $this->sender->getName())
209
            ->addTo($email->getEmail(), $commonName->getCommonName())
210
            ->setSubject($subject)
211
            ->setBody($body, 'text/html', 'utf-8');
212
213
        $this->mailer->send($message);
214
    }
215
}
216