ExceptionController::getPageTitleAndDescription()   B
last analyzed

Complexity

Conditions 7
Paths 10

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.5386
c 0
b 0
f 0
cc 7
nc 10
nop 1
1
<?php
2
3
/**
4
 * Copyright 2018 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupRa\RaBundle\Controller;
20
21
use Exception;
22
use Surfnet\StepupBundle\Controller\ExceptionController as BaseExceptionController;
23
use Surfnet\StepupRa\RaBundle\Exception\LoaTooLowException;
24
use Surfnet\StepupRa\RaBundle\Exception\MissingRequiredAttributeException;
25
use Surfnet\StepupRa\RaBundle\Exception\UserNotRaException;
26
use Symfony\Component\HttpKernel\Exception\HttpException;
27
28
final class ExceptionController extends BaseExceptionController
29
{
30
    /**
31
     * @param Exception $exception
32
     * @return array View parameters 'title' and 'description'
33
     */
34
    protected function getPageTitleAndDescription(Exception $exception)
35
    {
36
        $translator = $this->getTranslator();
37
38
        if ($exception instanceof HttpException) {
39
            $parent = $exception->getPrevious();
40
41
            if ($parent instanceof UserNotRaException) {
42
                $title = $translator->trans('stepup.error.user_not_ra.title');
43
                $description = $translator->trans('stepup.error.user_not_ra.description');
44
            } elseif ($parent instanceof LoaTooLowException) {
45
                $title = $translator->trans('stepup.error.loa_too_low.title');
46
                $description = $translator->trans('stepup.error.loa_too_low.description');
47
            } elseif ($parent instanceof MissingRequiredAttributeException) {
48
                $title = $translator->trans('stepup.error.missing_required_attribute.title');
49
                $description = $parent->getMessage();
50
            }
51
        }
52
53
        if (isset($title) && isset($description)) {
54
            return [
55
                'title' => $title,
56
                'description' => $description,
57
            ];
58
        }
59
60
        return parent::getPageTitleAndDescription($exception);
61
    }
62
}
63