GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SecondFactorTypeTranslationService::translate()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
rs 9.568
cc 3
nc 4
nop 2
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\StepupBundle\Service;
20
21
use Surfnet\StepupBundle\Value\Provider\ViewConfigCollection;
22
use Symfony\Component\Translation\TranslatorInterface;
23
24
/**
25
 * Provide translations for second factor types like yubikey, tiqr, sms, u2f, ..
26
 *
27
 * Generic tokens (gssp) are translated from the YAML configuration provided for them. Where the hard coded types (sms,
28
 * yubikey and u2f) are translated using the Symfony translator.
29
 *
30
 * Translations should be provided in the translations file for this project and should follow the format specified in
31
 * the 'translationIdFormat' field.
32
 */
33
class SecondFactorTypeTranslationService
34
{
35
    /**
36
     * @var ViewConfigCollection
37
     */
38
    private $gsspConfigCollection;
39
40
    /**
41
     * @var TranslatorInterface
42
     */
43
    private $translator;
44
45
    public function __construct(
46
        ViewConfigCollection $gsspConfigCollection,
47
        TranslatorInterface $translator
48
    ) {
49
        $this->gsspConfigCollection = $gsspConfigCollection;
50
        $this->translator = $translator;
51
    }
52
53
    /**
54
     * @param string $secondFactorTypeId
55
     * @param string $translationIdFormat The format used to read a translation from the Symfony translator. Should be
56
     *                                    compatible with sprintf. Where one string parameter represents the seconf
57
     *                                    factor type. Example 'ra.gssp_token.%s.title'
58
     * @return string
59
     */
60
    public function translate($secondFactorTypeId, $translationIdFormat)
61
    {
62
        $translationId = sprintf($translationIdFormat, $secondFactorTypeId);
63
64
        if ($this->gsspConfigCollection->isGssp($secondFactorTypeId)) {
65
            // Attempt a gssp translation based on the gssp config
66
            $translation = $this->gsspConfigCollection
0 ignored issues
show
Bug introduced by
The method getTitle() does not seem to exist on object<Surfnet\StepupBun...er\ViewConfigInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
                ->getByIdentifier($secondFactorTypeId)
68
                ->getTitle();
69
        } else {
70
            // Attempt a regular symfony translation for any non gssp sf type.
71
            $translation = $this->translator->trans($translationId);
72
        }
73
74
        // If unable to translate, return the translation id, the user of this translator should decide how to handle
75
        // this situation.
76
        if ($translationId === $translation) {
77
            return $secondFactorTypeId;
78
        }
79
80
        return $translation;
81
    }
82
}
83