Completed
Push — master ( 5467e4...183ea4 )
by Boy
05:06 queued 01:02
created

RaSecondFactor::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
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\StepupMiddleware\ApiBundle\Identity\Entity;
20
21
use Doctrine\ORM\Mapping as ORM;
22
use JsonSerializable;
23
use Surfnet\Stepup\Identity\Value\CommonName;
24
use Surfnet\Stepup\Identity\Value\Email;
25
use Surfnet\Stepup\Identity\Value\Institution;
26
use Surfnet\StepupMiddleware\ApiBundle\Identity\Value\SecondFactorStatus;
27
28
/**
29
 * A second factor as displayed in the registration authority application. One exists for every second factor,
30
 * regardless of state. As such, it sports a status property, indicating whether its vetted, revoked etc.
31
 *
32
 * @ORM\Entity(repositoryClass="Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\RaSecondFactorRepository")
33
 * @ORM\Table(
34
 *      indexes={
35
 *          @ORM\Index(name="idx_ra_second_factor_second_factor_id", columns={"second_factor_id"}),
36
 *          @ORM\Index(name="idx_ra_second_factor_identity_id", columns={"identity_id"}),
37
 *          @ORM\Index(name="idx_ra_second_factor_institution", columns={"institution"}),
38
 *          @ORM\Index(name="idx_ra_second_factor_name", columns={"name"}, flags={"FULLTEXT"}),
39
 *          @ORM\Index(name="idx_ra_second_factor_email", columns={"email"}, flags={"FULLTEXT"}),
40
 *      }
41
 * )
42
 */
43
class RaSecondFactor implements JsonSerializable
44
{
45
    /**
46
     * @ORM\Id
47
     * @ORM\Column(length=36)
48
     *
49
     * @var string The second factor's ID (UUID).
50
     */
51
    public $id;
52
53
    /**
54
     * @ORM\Column(length=16)
55
     *
56
     * @var string
57
     */
58
    public $type;
59
60
    /**
61
     * @ORM\Column(length=255)
62
     *
63
     * @var string The ID of the specific instance of second factor type (ie. phone number, Yubikey public ID).
64
     */
65
    public $secondFactorId;
66
67
    /**
68
     * @ORM\Column(type="stepup_second_factor_status")
69
     *
70
     * @var SecondFactorStatus
71
     */
72
    public $status;
73
74
    /**
75
     * @ORM\Column(length=36)
76
     *
77
     * @var string
78
     */
79
    public $identityId;
80
81
    /**
82
     * @ORM\Column(type="institution")
83
     *
84
     * @var \Surfnet\Stepup\Identity\Value\Institution
85
     */
86
    public $institution;
87
88
    /**
89
     * The name of the registrant.
90
     *
91
     * @ORM\Column(type="stepup_common_name")
92
     *
93
     * @var \Surfnet\Stepup\Identity\Value\CommonName
94
     */
95
    public $name;
96
97
    /**
98
     * The e-mail of the registrant.
99
     *
100
     * @ORM\Column(type="stepup_email")
101
     *
102
     * @var \Surfnet\Stepup\Identity\Value\Email
103
     */
104
    public $email;
105
106
    /**
107
     * @param string $id
108
     * @param string $type
109
     * @param string $secondFactorId
110
     * @param string $identityId
111
     * @param Institution $institution
112
     * @param CommonName $name
113
     * @param Email $email
114
     */
115
    public function __construct(
116
        $id,
117
        $type,
118
        $secondFactorId,
119
        $identityId,
120
        Institution $institution,
121
        CommonName $name,
122
        Email $email
123
    ) {
124
        $this->id = $id;
125
        $this->type = $type;
126
        $this->secondFactorId = $secondFactorId;
127
        $this->status = SecondFactorStatus::unverified();
128
        $this->identityId = $identityId;
129
        $this->name = $name;
130
        $this->email = $email;
131
        $this->institution = $institution;
132
    }
133
134
    public function jsonSerialize()
135
    {
136
        return [
137
            'id'               => $this->id,
138
            'type'             => $this->type,
139
            'second_factor_id' => $this->secondFactorId,
140
            'status'           => (string) $this->status,
141
            'identity_id'      => $this->identityId,
142
            'name'             => $this->name,
143
            'email'            => $this->email,
144
            'institution'      => $this->institution,
145
        ];
146
    }
147
}
148