InstitutionCollection::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2018 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\Stepup\Identity\Entity;
20
21
use Surfnet\Stepup\Identity\Collection\InstitutionCollection as Institutions;
22
use Surfnet\Stepup\Identity\Value\Institution;
23
24
final class InstitutionCollection
25
{
26
    private array $institutions = [];
27
28
    public function set(Institution $institution): void
29
    {
30
        $this->institutions[(string)$institution] = $institution;
31
    }
32
33
    public function update(Institutions $institutions): void
34
    {
35
        foreach ($institutions as $institution) {
36
            $this->institutions[(string)$institution] = $institution;
37
        }
38
    }
39
40
    public function get(Institution $institution): Institution
41
    {
42
        return $this->institutions[(string)$institution];
43
    }
44
45
    public function exists(Institution $institution): bool
46
    {
47
        return array_key_exists((string)$institution, $this->institutions);
48
    }
49
50
    public function remove(Institution $institution): void
51
    {
52
        unset($this->institutions[(string)$institution]);
53
    }
54
55
    public function count(): int
56
    {
57
        return count($this->institutions);
58
    }
59
60
    /**
61
     * @return Institution[]
62
     */
63
    public function institutions(): array
64
    {
65
        return $this->institutions;
66
    }
67
}
68