Institution::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
0 ignored issues
show
Coding Style introduced by
The file-level docblock must follow the opening PHP tag in the file header
Loading history...
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
 */
20
21
namespace Surfnet\Stepup\Identity\Value;
22
23
use JsonSerializable;
24
use Stringable;
25
use Surfnet\Stepup\Exception\InvalidArgumentException;
26
27
final class Institution implements JsonSerializable, Stringable
28
{
29
    private readonly string $institution;
30
31
    /**
32
     * @param string $institution may not be an empty string
33
     */
34
    public function __construct(string $institution)
35
    {
36
        if (trim($institution) === '') {
37
            throw InvalidArgumentException::invalidType('non-empty string', 'institution', $institution);
38
        }
39
40
        $this->institution = strtolower(trim($institution));
0 ignored issues
show
Bug introduced by
The property institution is declared read-only in Surfnet\Stepup\Identity\Value\Institution.
Loading history...
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getInstitution(): string
47
    {
48
        return $this->institution;
49
    }
50
51
    public function equals(Institution $otherInstitution): bool
52
    {
53
        return $this->institution === $otherInstitution->institution;
54
    }
55
56
    public function jsonSerialize(): string
57
    {
58
        return $this->institution;
59
    }
60
61
    public function __toString(): string
62
    {
63
        return $this->institution;
64
    }
65
}
66