Failed Conditions
Pull Request — master (#319)
by Guilherme
08:18
created

SupportPerson::getEmailVerifiedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\IdentifiablePersonInterface;
18
use LoginCidadao\CoreBundle\Model\PersonInterface;
19
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
20
21
class SupportPerson implements IdentifiablePersonInterface
22
{
23
    /** @var mixed */
24
    private $id;
25
26
    /** @var string */
27
    private $firstName;
28
29
    /** @var string */
30
    private $lastName;
31
32
    /** @var PersonalData */
33
    private $birthday;
34
35
    /** @var PersonalData */
36
    private $cpf;
37
38
    /** @var PersonalData */
39
    private $email;
40
41
    /** @var \DateTimeInterface */
42
    private $emailVerifiedAt;
43
44
    /** @var PersonalData */
45
    private $phoneNumber;
46
47
    /** @var \DateTimeInterface */
48
    private $lastPasswordResetRequest;
49
50
    /** @var bool */
51
    private $has2FA;
52
53
    /** @var array */
54
    private $thirdPartyConnections = [];
55
56
    /** @var bool */
57
    private $isEnabled;
58
59
    /** @var \DateTimeInterface */
60
    private $lastUpdate;
61
62
    /** @var \DateTimeInterface */
63
    private $createdAt;
64
65
    /**
66
     * SupportPerson constructor.
67
     * @param PersonInterface|Person $person
68
     * @param AuthorizationCheckerInterface $authorizationChecker
69
     */
70 4
    public function __construct(PersonInterface $person, AuthorizationCheckerInterface $authorizationChecker)
71
    {
72 4
        $this->id = $person->getId();
73 4
        $this->firstName = $person->getFirstName();
74 4
        $this->lastName = $person->getSurname();
75 4
        $this->emailVerifiedAt = $person->getEmailConfirmedAt();
76 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

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