AvailableTokenCollection   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 40
rs 10
c 1
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sortCollection() 0 8 3
A from() 0 13 3
A getData() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Copyright 2018 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\SelfServiceBundle\Value;
22
23
/**
24
 * AvailableTokenCollection is used in the display second factor types view to be able to handle GSSP and non GSSP
25
 * tokens in a more homogeneous manner.
26
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
27
class AvailableTokenCollection
28
{
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @var AvailableTokenInterface[]
31
     */
32
    private array $collection = [];
0 ignored issues
show
Coding Style introduced by
Private member variable "collection" must be prefixed with an underscore
Loading history...
33
34
    public static function from(array $builtInTokens, array $gsspTokens): self
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function from()
Loading history...
35
    {
36
        $collection = new self();
37
38
        foreach ($builtInTokens as $token) {
39
            $collection->collection[$token] = BuiltInToken::fromSecondFactorType($token);
40
        }
41
42
        foreach ($gsspTokens as $type => $token) {
43
            $collection->collection[$type] = GsspToken::fromViewConfig($token, $type);
44
        }
45
46
        return $collection;
47
    }
48
49
    /**
50
     * Sorts and returns the available tokens
51
     * @return AvailableTokenInterface[]
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
52
     */
53
    public function getData(): array
54
    {
55
        $this->sortCollection();
56
        return $this->collection;
57
    }
58
59
    private function sortCollection(): void
0 ignored issues
show
Coding Style introduced by
Private method name "AvailableTokenCollection::sortCollection" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function sortCollection()
Loading history...
60
    {
61
        // The collection is first sorted by LoA level and then in alphabetic order.
62
        uasort($this->collection, function (AvailableTokenInterface $a, AvailableTokenInterface $b): int {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
63
            if ($a->getLoaLevel() === $b->getLoaLevel()) {
64
                return strcmp((string) $a->getType(), (string) $b->getType());
65
            }
66
            return $a->getLoaLevel() > $b->getLoaLevel() ? 1 : -1;
67
        });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
68
    }
69
}
70