DocumentNumber   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A unknown() 0 3 1
A equals() 0 3 1
A getDocumentNumber() 0 3 1
A __toString() 0 3 1
A jsonSerialize() 0 3 1
A __construct() 0 7 3
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 DocumentNumber implements JsonSerializable, Stringable
28
{
29
    private readonly string $documentNumber;
30
31
    /**
32
     * @return self
33
     */
34
    public static function unknown(): self
35
    {
36
        return new self('—');
37
    }
38
39
    public function __construct(string $documentNumber)
40
    {
41
        if ($documentNumber === '' || $documentNumber === '0') {
42
            throw InvalidArgumentException::invalidType('non-empty string', 'documentNumber', $documentNumber);
43
        }
44
45
        $this->documentNumber = $documentNumber;
0 ignored issues
show
Bug introduced by
The property documentNumber is declared read-only in Surfnet\Stepup\Identity\Value\DocumentNumber.
Loading history...
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getDocumentNumber(): string
52
    {
53
        return $this->documentNumber;
54
    }
55
56
    public function __toString(): string
57
    {
58
        return $this->documentNumber;
59
    }
60
61
    public function equals(DocumentNumber $other): bool
62
    {
63
        return $this->documentNumber === $other->documentNumber;
64
    }
65
66
    public function jsonSerialize(): string
67
    {
68
        return $this->documentNumber;
69
    }
70
}
71