Passed
Pull Request — main (#308)
by Paul
18:42 queued 09:10
created

MetadataFactoryCollection::getByIdentifier()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Copyright 2023 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\SamlBundle\Metadata\MetadataFactory;
24
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Exception\MetadataFactoryNotFoundException;
25
26
class MetadataFactoryCollection
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class MetadataFactoryCollection
Loading history...
27
{
28
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29
     * @var array<string, MetadataFactory>
30
     */
31
    private array $metadataFactoryCollection = [];
0 ignored issues
show
Coding Style introduced by
Private member variable "metadataFactoryCollection" must be prefixed with an underscore
Loading history...
32
33
    public function getByIdentifier(string $provider): MetadataFactory
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getByIdentifier()
Loading history...
34
    {
35
        if (!$this->has($provider)) {
36
            throw new MetadataFactoryNotFoundException(
37
                message: "The provider {$provider} does not exist in the collection"
38
            );
39
        }
40
41
        return $this->metadataFactoryCollection[$provider];
42
    }
43
44
    private function has(string $provider): bool
0 ignored issues
show
Coding Style introduced by
Private method name "MetadataFactoryCollection::has" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function has()
Loading history...
45
    {
46
        return array_key_exists($provider, $this->metadataFactoryCollection);
47
    }
48
49
    public function add(string $provider, MetadataFactory $factory): void
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function add()
Loading history...
50
    {
51
        if ($this->has($provider)) {
52
            return;
53
        }
54
        $this->metadataFactoryCollection[$provider] = $factory;
55
    }
56
}
57