Code Duplication    Length = 25-27 lines in 2 locations

src/Surfnet/StepupSelfService/SelfServiceBundle/Security/Authentication/Provider/SamlProvider.php 2 locations

@@ 146-170 (lines=25) @@
143
     * @param AssertionAdapter $translatedAssertion
144
     * @return string
145
     */
146
    private function getEmail(AssertionAdapter $translatedAssertion)
147
    {
148
        $emails = $translatedAssertion->getAttributeValue('mail');
149
150
        if (empty($emails)) {
151
            throw new BadCredentialsException(
152
                'No schacHomeOrganization provided'
153
            );
154
        }
155
156
        if (count($emails) > 1) {
157
            $this->logger->notice('Multiple emails provided, picking first one', ['emailsCount' => count($emails)]);
158
        }
159
160
        $email = $emails[0];
161
162
        if (!is_string($email)) {
163
            $this->logger->notice('Received invalid email');
164
            throw new BadCredentialsException(
165
                'email is not a string'
166
            );
167
        }
168
169
        return $email;
170
    }
171
172
    /**
173
     * @param AssertionAdapter $translatedAssertion
@@ 176-202 (lines=27) @@
173
     * @param AssertionAdapter $translatedAssertion
174
     * @return string
175
     */
176
    private function getInstitution(AssertionAdapter $translatedAssertion)
177
    {
178
        $institutions = $translatedAssertion->getAttributeValue('schacHomeOrganization');
179
180
        if (empty($institutions)) {
181
            throw new BadCredentialsException(
182
                'No schacHomeOrganization provided'
183
            );
184
        }
185
186
        if (count($institutions) > 1) {
187
            throw new BadCredentialsException(
188
                'Multiple schacHomeOrganizations provided'
189
            );
190
        }
191
192
        $institution = $institutions[0];
193
194
        if (!is_string($institution)) {
195
            $this->logger->notice('Received invalid schacHomeOrganization', ['schacHomeOrganization' => $institution]);
196
            throw new BadCredentialsException(
197
                'schacHomeOrganization is not a string'
198
            );
199
        }
200
201
        return $institution;
202
    }
203
}
204