RaCandidate::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 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
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
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\IdentityId;
26
use Surfnet\Stepup\Identity\Value\Institution;
27
use Surfnet\Stepup\Identity\Value\NameId;
28
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\RaCandidateRepository;
29
30
/**
31
 * Be aware that this entity is used for the RA Candidate presentation only. This entity shouldn't be used to store any RA candidates.
32
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
33
#[ORM\Entity(repositoryClass: RaCandidateRepository::class, readOnly: true)]
34
class RaCandidate implements JsonSerializable
35
{
36
    /**
37
     *
38
     * @var string
39
     */
40
    #[ORM\Id]
41
    #[ORM\Column(length: 36)]
42
    public string $identityId;
43
44
    /**
45
     *
46
     * @var Institution
47
     */
48
    #[ORM\Id]
49
    #[ORM\Column(type: 'institution')]
50
    public Institution $raInstitution;
51
52
    /**
53
     * @var Institution
54
     */
55
    #[ORM\Column(type: 'institution')]
56
    public Institution $institution;
57
58
    /**
59
     * @var NameId
60
     */
61
    #[ORM\Column(type: 'stepup_name_id')]
62
    public NameId $nameId;
63
64
    /**
65
     * @var CommonName
66
     */
67
    #[ORM\Column(type: 'stepup_common_name')]
68
    public CommonName $commonName;
69
70
    /**
71
     * @var Email
72
     */
73
    #[ORM\Column(type: 'stepup_email')]
74
    public Email $email;
75
76
    private function __construct()
77
    {
78
    }
79
80
    public static function nominate(
81
        IdentityId $identityId,
82
        Institution $institution,
83
        NameId $nameId,
84
        CommonName $commonName,
85
        Email $email,
86
        Institution $raInstitution,
87
    ): self {
88
        $candidate = new self();
89
        $candidate->identityId = (string)$identityId;
90
        $candidate->institution = $institution;
91
        $candidate->nameId = $nameId;
92
        $candidate->commonName = $commonName;
93
        $candidate->email = $email;
94
        $candidate->raInstitution = $raInstitution;
95
96
        return $candidate;
97
    }
98
99
    public function jsonSerialize(): array
100
    {
101
        return [
102
            'identity_id' => $this->identityId,
103
            'institution' => $this->institution,
104
            'common_name' => $this->commonName,
105
            'email' => $this->email,
106
            'name_id' => $this->nameId,
107
            'ra_institution' => $this->raInstitution,
108
        ];
109
    }
110
}
111