Passed
Push — feature/build-and-publish-test... ( 5abced...ea0709 )
by
unknown
12:17 queued 03:44
created

ProviderRepository   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 43
rs 10
c 2
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 2
A __construct() 0 2 1
A addProvider() 0 10 2
A has() 0 3 1
A getAll() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Copyright 2014 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\StepupSelfService\SamlStepupProviderBundle\Exception\InvalidConfigurationException;
24
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Exception\UnknownProviderException;
25
26
final class ProviderRepository
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class ProviderRepository
Loading history...
27
{
28
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29
     * @var Provider[]
30
     */
31
    private array $providers = [];
0 ignored issues
show
Coding Style introduced by
Private member variable "providers" must be prefixed with an underscore
Loading history...
32
33
    public function __construct()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
34
    {
35
    }
36
37
    public function addProvider(Provider $provider): void
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function addProvider()
Loading history...
38
    {
39
        if ($this->has($provider->getName())) {
40
            throw new InvalidConfigurationException(sprintf(
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...
41
                'Provider "%s" has already been added to the repository',
42
                $provider->getName()
43
            ));
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...
44
        }
45
46
        $this->providers[$provider->getName()] = $provider;
47
    }
48
49
    public function has(string $providerName): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function has()
Loading history...
50
    {
51
        return array_key_exists($providerName, $this->providers);
52
    }
53
54
    public function get(string $providerName): Provider
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function get()
Loading history...
55
    {
56
        if (!$this->has($providerName)) {
57
            throw UnknownProviderException::create($providerName, array_keys($this->providers));
58
        }
59
60
        return $this->providers[$providerName];
61
    }
62
63
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
64
     * @return Provider[]
65
     */
66
    public function getAll(): array
67
    {
68
        return $this->providers;
69
    }
70
}
71