Completed
Push — issue#699 ( 11c53a...fbd8dd )
by Guilherme
05:46
created

SupportPerson   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 221
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 68
dl 0
loc 221
ccs 70
cts 70
cp 1
rs 10
c 0
b 0
f 0
wmc 24

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 30 3
A getPhoneNumber() 0 3 1
A getLastPasswordResetRequest() 0 3 1
A getThirdPartyConnections() 0 3 1
A getLastName() 0 3 1
A getEmail() 0 3 1
A getCreatedAt() 0 3 1
A getCpf() 0 3 1
A getBirthday() 0 3 1
A getEmailVerifiedAt() 0 3 1
A getId() 0 3 1
A setPhoneNumber() 0 11 3
A getName() 0 3 1
A isEnabled() 0 3 1
A setBirthday() 0 11 3
A getFirstName() 0 3 1
A getLastUpdate() 0 3 1
A has2FA() 0 3 1
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\SupportBundle\Model;
12
13
use libphonenumber\PhoneNumber;
14
use libphonenumber\PhoneNumberFormat;
15
use libphonenumber\PhoneNumberUtil;
16
use LoginCidadao\CoreBundle\Entity\Person;
17
use LoginCidadao\CoreBundle\Model\PersonInterface;
18
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
19
20
class SupportPerson
21
{
22
    /** @var mixed */
23
    private $id;
24
25
    /** @var string */
26
    private $firstName;
27
28
    /** @var string */
29
    private $lastName;
30
31
    /** @var PersonalData */
32
    private $birthday;
33
34
    /** @var PersonalData */
35
    private $cpf;
36
37
    /** @var PersonalData */
38
    private $email;
39
40
    /** @var \DateTimeInterface */
41
    private $emailVerifiedAt;
42
43
    /** @var PersonalData */
44
    private $phoneNumber;
45
46
    /** @var \DateTimeInterface */
47
    private $lastPasswordResetRequest;
48
49
    /** @var bool */
50
    private $has2FA;
51
52
    /** @var array */
53
    private $thirdPartyConnections = [];
54
55
    /** @var bool */
56
    private $isEnabled;
57
58
    /** @var \DateTimeInterface */
59
    private $lastUpdate;
60
61
    /** @var \DateTimeInterface */
62
    private $createdAt;
63
64
    /**
65
     * SupportPerson constructor.
66
     * @param PersonInterface|Person $person
67
     * @param AuthorizationCheckerInterface $authorizationChecker
68
     */
69 4
    public function __construct(PersonInterface $person, AuthorizationCheckerInterface $authorizationChecker)
70
    {
71 4
        $this->id = $person->getId();
72 4
        $this->firstName = $person->getFirstName();
73 4
        $this->lastName = $person->getSurname();
74 4
        $this->emailVerifiedAt = $person->getEmailConfirmedAt();
75 4
        $this->lastPasswordResetRequest = $person->getPasswordRequestedAt();
0 ignored issues
show
Bug introduced by
The method getPasswordRequestedAt() does not exist on LoginCidadao\CoreBundle\Model\PersonInterface. Did you maybe mean getPassword()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

75
        /** @scrutinizer ignore-call */ 
76
        $this->lastPasswordResetRequest = $person->getPasswordRequestedAt();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
76 4
        $this->has2FA = $person->getGoogleAuthenticatorSecret() !== null;
77 4
        $this->isEnabled = $person->isEnabled();
78 4
        $this->lastUpdate = $person->getUpdatedAt();
79 4
        $this->createdAt = $person->getCreatedAt();
80
81 4
        $this->thirdPartyConnections = [
82 4
            'facebook' => $person->getFacebookId() !== null,
83 4
            'google' => $person->getGoogleId() !== null,
84 4
            'twitter' => $person->getTwitterId() !== null,
85
        ];
86
87 4
        if ($authorizationChecker->isGranted('ROLE_VIEW_USERS_CPF')) {
88 1
            $this->cpf = PersonalData::createWithValue('cpf', $person->getCpf());
89
        } else {
90 3
            $this->cpf = PersonalData::createWithoutValue('cpf', $person->getCpf());
91
        }
92 4
        if ($authorizationChecker->isGranted('ROLE_SUPPORT_VIEW_EMAIL')) {
93 1
            $this->email = PersonalData::createWithValue('email', $person->getEmailCanonical());
94
        } else {
95 3
            $this->email = PersonalData::createWithoutValue('email', $person->getEmailCanonical());
96
        }
97 4
        $this->setPhoneNumber($person, $authorizationChecker);
98 4
        $this->setBirthday($person, $authorizationChecker);
99 4
    }
100
101 4
    private function setPhoneNumber(PersonInterface $person, AuthorizationCheckerInterface $authorizationChecker)
102
    {
103 4
        $phoneNumber = $person->getMobile();
104 4
        if ($phoneNumber instanceof PhoneNumber) {
105 2
            $phoneUtil = PhoneNumberUtil::getInstance();
106 2
            $phoneNumber = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
107
        }
108 4
        if ($authorizationChecker->isGranted('ROLE_SUPPORT_VIEW_PHONE')) {
109 1
            $this->phoneNumber = PersonalData::createWithValue('phoneNumber', $phoneNumber);
110
        } else {
111 3
            $this->phoneNumber = PersonalData::createWithoutValue('phoneNumber', $phoneNumber);
112
        }
113 4
    }
114
115 4
    private function setBirthday(PersonInterface $person, AuthorizationCheckerInterface $authorizationChecker)
116
    {
117 4
        $birthday = $person->getBirthdate();
118 4
        if ($birthday instanceof \DateTimeInterface) {
0 ignored issues
show
introduced by
$birthday is always a sub-type of DateTimeInterface.
Loading history...
119 2
            $birthday = $birthday->format('Y-m-d');
120
        }
121
122 4
        if ($authorizationChecker->isGranted('ROLE_SUPPORT_VIEW_BIRTHDAY')) {
123 1
            $this->birthday = PersonalData::createWithValue('birthday', $birthday);
124
        } else {
125 3
            $this->birthday = PersonalData::createWithoutValue('birthday', $birthday);
126
        }
127 4
    }
128
129 1
    public function getName(): string
130
    {
131 1
        return $this->getFirstName() ?? $this->getId();
132
    }
133
134 3
    public function getId()
135
    {
136 3
        return $this->id;
137
    }
138
139
    /**
140
     * @return string
141
     */
142 3
    public function getFirstName(): ?string
143
    {
144 3
        return $this->firstName;
145
    }
146
147
    /**
148
     * @return string
149
     */
150 2
    public function getLastName(): ?string
151
    {
152 2
        return $this->lastName;
153
    }
154
155
    /**
156
     * @return PersonalData
157
     */
158 2
    public function getBirthday(): PersonalData
159
    {
160 2
        return $this->birthday;
161
    }
162
163
    /**
164
     * @return PersonalData
165
     */
166 2
    public function getCpf(): PersonalData
167
    {
168 2
        return $this->cpf;
169
    }
170
171
    /**
172
     * @return PersonalData
173
     */
174 2
    public function getEmail(): PersonalData
175
    {
176 2
        return $this->email;
177
    }
178
179
    /**
180
     * @return \DateTimeInterface
181
     */
182 2
    public function getEmailVerifiedAt(): ?\DateTimeInterface
183
    {
184 2
        return $this->emailVerifiedAt;
185
    }
186
187
    /**
188
     * @return PersonalData
189
     */
190 2
    public function getPhoneNumber(): PersonalData
191
    {
192 2
        return $this->phoneNumber;
193
    }
194
195
    /**
196
     * @return \DateTimeInterface
197
     */
198 2
    public function getLastPasswordResetRequest(): ?\DateTimeInterface
199
    {
200 2
        return $this->lastPasswordResetRequest;
201
    }
202
203
    /**
204
     * @return bool
205
     */
206 2
    public function has2FA(): bool
207
    {
208 2
        return $this->has2FA;
209
    }
210
211
    /**
212
     * @return array
213
     */
214 2
    public function getThirdPartyConnections(): array
215
    {
216 2
        return $this->thirdPartyConnections;
217
    }
218
219
    /**
220
     * @return bool
221
     */
222 2
    public function isEnabled(): bool
223
    {
224 2
        return $this->isEnabled;
225
    }
226
227
    /**
228
     * @return \DateTimeInterface
229
     */
230 2
    public function getLastUpdate(): \DateTimeInterface
231
    {
232 2
        return $this->lastUpdate;
233
    }
234
235
    /**
236
     * @return \DateTimeInterface
237
     */
238 2
    public function getCreatedAt(): \DateTimeInterface
239
    {
240 2
        return $this->createdAt;
241
    }
242
}
243