Passed
Push — master ( e7acbe...c65cd9 )
by Esteban De La Fuente
19:00
created

PartyIdentifier::getSchemeName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * LibreDTE: Biblioteca PHP (Núcleo).
7
 * Copyright (C) LibreDTE <https://www.libredte.cl>
8
 *
9
 * Este programa es software libre: usted puede redistribuirlo y/o modificarlo
10
 * bajo los términos de la Licencia Pública General Affero de GNU publicada por
11
 * la Fundación para el Software Libre, ya sea la versión 3 de la Licencia, o
12
 * (a su elección) cualquier versión posterior de la misma.
13
 *
14
 * Este programa se distribuye con la esperanza de que sea útil, pero SIN
15
 * GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD
16
 * PARA UN PROPÓSITO DETERMINADO. Consulte los detalles de la Licencia Pública
17
 * General Affero de GNU para obtener una información más detallada.
18
 *
19
 * Debería haber recibido una copia de la Licencia Pública General Affero de
20
 * GNU junto a este programa.
21
 *
22
 * En caso contrario, consulte <http://www.gnu.org/licenses/agpl.html>.
23
 */
24
25
namespace libredte\lib\Core\Package\Billing\Component\Exchange\Entity;
26
27
use libredte\lib\Core\Package\Billing\Component\Exchange\Contract\PartyIdentifierInterface;
28
29
/**
30
 * Entidad para representar el identificador único de un participante.
31
 */
32
class PartyIdentifier implements PartyIdentifierInterface
33
{
34
    /**
35
     * Identificador del esquema del valor.
36
     *
37
     * @var string
38
     */
39
    protected string $schemeId;
40
41
    /**
42
     * Valor del identificador único del participante.
43
     *
44
     * @var string
45
     */
46
    protected string $value;
47
48
    /**
49
     * Mapa de identificadores de esquema a su nombre.
50
     *
51
     * @var array <string, string>
52
     */
53
    protected const SCHEME_NAMES = [
54
        'CL-RUT' => 'Rol Único Tributario (RUT) de Chile',
55
        'EMAIL' => 'Correo electrónico',
56
    ];
57
58
    /**
59
     * Mapa de identificadores de esquema a la autoridad que lo administra.
60
     *
61
     * @var array <string, string>
62
     */
63
    protected const AUTHORITIES = [
64
        'CL-RUT' => 'CL-SII',
65
        'EMAIL' => 'INTERNET',
66
    ];
67
68
    /**
69
     * Constructor del identificador único de un participante.
70
     *
71
     * @param string $value
72
     * @param string $schemeId
73
     */
74
    public function __construct(string $value, string $schemeId = 'CL-RUT')
75
    {
76
        $this->schemeId = $schemeId;
77
        $this->value = $value;
78
    }
79
80
    /**
81
     * {@inheritDoc}
82
     */
83
    public function getId(): string
84
    {
85
        return $this->schemeId . ':' . $this->value;
86
    }
87
88
    /**
89
     * {@inheritDoc}
90
     */
91
    public function getSchemeId(): string
92
    {
93
        return $this->schemeId;
94
    }
95
96
    /**
97
     * {@inheritDoc}
98
     */
99
    public function getSchemeName(): string
100
    {
101
        return self::SCHEME_NAMES[$this->schemeId] ?? $this->schemeId;
102
    }
103
104
    /**
105
     * {@inheritDoc}
106
     */
107
    public function getValue(): string
108
    {
109
        return $this->value;
110
    }
111
112
    /**
113
     * {@inheritDoc}
114
     */
115
    public function getAuthority(): string
116
    {
117
        return self::AUTHORITIES[$this->schemeId] ?? $this->schemeId;
118
    }
119
}
120