Code Duplication    Length = 46-46 lines in 2 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