Passed
Push — feature/symfony6-upgrade ( 12c641...0505e5 )
by Paul
06:48
created

MetadataFactoryCollection::add()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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