ViewConfig::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 14
dl 0
loc 16
rs 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Copyright 2017 SURFnet bv
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
20
21
namespace Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider;
22
23
use Surfnet\StepupBundle\Value\Provider\ViewConfigInterface;
24
use Surfnet\StepupSelfService\SelfServiceBundle\Exception\LogicException;
25
use Symfony\Component\HttpFoundation\RequestStack;
26
27
class ViewConfig implements ViewConfigInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class ViewConfig
Loading history...
28
{
29
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $requestStack should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $alt should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $title should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $description should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $buttonUse should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $initiateTitle should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $initiateButton should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $explanation should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $authnFailed should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $popFailed should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $loa should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $logo should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $androidUrl should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $iosUrl should have a doc-comment as per coding-style.
Loading history...
30
     * The arrays are arrays of translated text, indexed on locale.
31
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
32
     */
33
    public function __construct(
34
        private readonly RequestStack $requestStack,
35
        private readonly string       $loa,
36
        private readonly string       $logo,
37
        private readonly string       $androidUrl,
38
        private readonly string       $iosUrl,
39
        private readonly array        $alt,
40
        private readonly array        $title,
41
        private readonly array        $description,
42
        private readonly array        $buttonUse,
43
        private readonly array        $initiateTitle,
44
        private readonly array        $initiateButton,
45
        private readonly array        $explanation,
46
        private readonly array        $authnFailed,
47
        private readonly array        $popFailed
48
    ) {
49
    }
50
51
    public function getLogo(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getLogo()
Loading history...
52
    {
53
        return $this->logo;
54
    }
55
56
    public function getLoa(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getLoa()
Loading history...
57
    {
58
        return $this->loa;
59
    }
60
61
    public function getTitle(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getTitle()
Loading history...
62
    {
63
        return $this->getTranslation($this->title);
64
    }
65
66
    public function getAlt(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getAlt()
Loading history...
67
    {
68
        return $this->getTranslation($this->alt);
69
    }
70
71
    public function getDescription(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getDescription()
Loading history...
72
    {
73
        return $this->getTranslation($this->description);
74
    }
75
76
    public function getButtonUse(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getButtonUse()
Loading history...
77
    {
78
        return $this->getTranslation($this->buttonUse);
79
    }
80
81
    public function getInitiateTitle(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getInitiateTitle()
Loading history...
82
    {
83
        return $this->getTranslation($this->initiateTitle);
84
    }
85
86
    public function getInitiateButton(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getInitiateButton()
Loading history...
87
    {
88
        return $this->getTranslation($this->initiateButton);
89
    }
90
91
    public function getExplanation(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getExplanation()
Loading history...
92
    {
93
        return $this->getTranslation($this->explanation);
94
    }
95
96
    public function getAuthnFailed(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getAuthnFailed()
Loading history...
97
    {
98
        return $this->getTranslation($this->authnFailed);
99
    }
100
101
    public function getPopFailed(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getPopFailed()
Loading history...
102
    {
103
        return $this->getTranslation($this->popFailed);
104
    }
105
106
    public function getAndroidUrl(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getAndroidUrl()
Loading history...
107
    {
108
        return $this->androidUrl;
109
    }
110
111
    public function getIosUrl(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getIosUrl()
Loading history...
112
    {
113
        return $this->iosUrl;
114
    }
115
116
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $translations should have a doc-comment as per coding-style.
Loading history...
117
     * @throws LogicException
118
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
119
    private function getTranslation(array $translations): mixed
0 ignored issues
show
Coding Style introduced by
Private method name "ViewConfig::getTranslation" must be prefixed with an underscore
Loading history...
120
    {
121
        $currentLocale = $this->requestStack->getCurrentRequest()->getLocale();
122
        if (isset($translations[$currentLocale])) {
123
            return $translations[$currentLocale];
124
        }
125
        throw new LogicException(
126
            sprintf(
127
                'The requested translation is not available in this language: %s. Available languages: %s',
128
                $currentLocale,
129
                implode(', ', array_keys($translations))
130
            )
131
        );
132
    }
133
}
134