Completed
Push — master ( 1e88b2...6b6b05 )
by Boy
03:57
created

ProviderRepository::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright 2014 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\StepupGateway\SamlStepupProviderBundle\Provider;
20
21
use Doctrine\Common\Collections\ArrayCollection;
22
use Surfnet\StepupGateway\SamlStepupProviderBundle\Exception\InvalidConfigurationException;
23
use Surfnet\StepupGateway\SamlStepupProviderBundle\Exception\UnknownProviderException;
24
25
/**
26
 * @todo discuss (im)mutability
0 ignored issues
show
Coding Style introduced by
Comment refers to a TODO task

This check looks TODO comments that have been left in the code.

``TODO``s show that something is left unfinished and should be attended to.

Loading history...
27
 */
28
final class ProviderRepository
29
{
30
    /**
31
     * @var <ArrayCollection>Provider
32
     */
33
    private $providers;
34
35
    public function __construct()
36
    {
37
        $this->providers = new ArrayCollection();
38
    }
39
40
    /**
41
     * @param Provider $provider
42
     */
43
    public function addProvider(Provider $provider)
44
    {
45
        if ($this->providers->containsKey($provider->getName())) {
46
            throw new InvalidConfigurationException(sprintf(
47
                'Provider "%s" has already been added to the repository',
48
                $provider->getName()
49
            ));
50
        }
51
52
        $this->providers->set($provider->getName(), $provider);
53
    }
54
55
    /**
56
     * @param string $providerName
57
     * @return bool
58
     */
59
    public function has($providerName)
60
    {
61
        return $this->providers->containsKey($providerName);
62
    }
63
64
    /**
65
     * @param string $providerName
66
     * @return Provider
67
     */
68
    public function get($providerName)
69
    {
70
        if (!$this->has($providerName)) {
71
            throw UnknownProviderException::create($providerName, $this->providers->getKeys());
72
        }
73
74
        return $this->providers->get($providerName);
75
    }
76
}
77