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\Service; |
12
|
|
|
|
13
|
|
|
use libphonenumber\PhoneNumber; |
14
|
|
|
use LoginCidadao\CoreBundle\Entity\PersonRepository; |
15
|
|
|
use LoginCidadao\CoreBundle\Entity\SentEmail; |
16
|
|
|
use LoginCidadao\CoreBundle\Entity\SentEmailRepository; |
17
|
|
|
use LoginCidadao\CoreBundle\Model\IdentifiablePersonInterface; |
18
|
|
|
use LoginCidadao\CoreBundle\Model\PersonInterface; |
19
|
|
|
use LoginCidadao\PhoneVerificationBundle\Service\PhoneVerificationServiceInterface; |
20
|
|
|
use LoginCidadao\SupportBundle\Exception\PersonNotFoundException; |
21
|
|
|
use LoginCidadao\SupportBundle\Model\PersonalData; |
22
|
|
|
use LoginCidadao\SupportBundle\Model\SupportPerson; |
23
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
24
|
|
|
|
25
|
|
|
class SupportHandler |
26
|
|
|
{ |
27
|
|
|
/** @var AuthorizationCheckerInterface */ |
28
|
|
|
private $authChecker; |
29
|
|
|
|
30
|
|
|
/** @var PhoneVerificationServiceInterface */ |
31
|
|
|
private $phoneVerificationService; |
32
|
|
|
|
33
|
|
|
/** @var PersonRepository */ |
34
|
|
|
private $personRepository; |
35
|
|
|
|
36
|
|
|
/** @var SentEmailRepository */ |
37
|
|
|
private $sentEmailRepository; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* SupportHandler constructor. |
41
|
|
|
* @param AuthorizationCheckerInterface $authChecker |
42
|
|
|
* @param PhoneVerificationServiceInterface $phoneVerificationService |
43
|
|
|
* @param PersonRepository $personRepository |
44
|
|
|
* @param SentEmailRepository $sentEmailRepository |
45
|
|
|
*/ |
46
|
7 |
|
public function __construct( |
47
|
|
|
AuthorizationCheckerInterface $authChecker, |
48
|
|
|
PhoneVerificationServiceInterface $phoneVerificationService, |
49
|
|
|
PersonRepository $personRepository, |
50
|
|
|
SentEmailRepository $sentEmailRepository |
51
|
|
|
) { |
52
|
7 |
|
$this->authChecker = $authChecker; |
53
|
7 |
|
$this->phoneVerificationService = $phoneVerificationService; |
54
|
7 |
|
$this->personRepository = $personRepository; |
55
|
7 |
|
$this->sentEmailRepository = $sentEmailRepository; |
56
|
7 |
|
} |
57
|
|
|
|
58
|
2 |
|
public function getSupportPerson($id): SupportPerson |
59
|
|
|
{ |
60
|
2 |
|
$person = $this->personRepository->find($id); |
61
|
2 |
|
if (!$person instanceof PersonInterface) { |
62
|
1 |
|
throw new PersonNotFoundException(); |
63
|
|
|
} |
64
|
|
|
|
65
|
1 |
|
return new SupportPerson($person, $this->authChecker); |
66
|
|
|
} |
67
|
|
|
|
68
|
3 |
|
public function getPhoneMetadata(IdentifiablePersonInterface $person): array |
69
|
|
|
{ |
70
|
|
|
/** @var PersonInterface $person */ |
71
|
3 |
|
$person = $this->personRepository->find($person->getId()); |
72
|
3 |
|
$phone = $person->getMobile(); |
73
|
|
|
|
74
|
3 |
|
if ($phone instanceof PhoneNumber) { |
75
|
2 |
|
$samePhoneCount = $this->personRepository->countByPhone($phone); |
76
|
2 |
|
$phoneVerification = $this->phoneVerificationService->getPhoneVerification($person, $phone); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return [ |
80
|
3 |
|
'samePhoneCount' => $samePhoneCount ?? 0, |
81
|
3 |
|
'verification' => $phoneVerification ?? null, |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
|
85
|
1 |
|
public function getInitialMessage($ticket): ?SentEmail |
86
|
|
|
{ |
87
|
|
|
/** @var SentEmail $sentEmail */ |
88
|
1 |
|
$sentEmail = $this->sentEmailRepository->findOneBy(['supportTicket' => $ticket]); |
89
|
|
|
|
90
|
1 |
|
return $sentEmail; |
91
|
|
|
} |
92
|
|
|
|
93
|
1 |
|
public function getValidationMap(SupportPerson $person): array |
94
|
|
|
{ |
95
|
1 |
|
return array_filter([ |
96
|
1 |
|
'cpf' => $this->personalDataToValidationArray($person->getCpf(), true), |
|
|
|
|
97
|
1 |
|
'birthday' => $this->personalDataToValidationArray($person->getBirthday(), true), |
|
|
|
|
98
|
1 |
|
'email' => $this->personalDataToValidationArray($person->getEmail(), true), |
|
|
|
|
99
|
1 |
|
'phoneNumber' => $this->personalDataToValidationArray($person->getPhoneNumber(), true), |
|
|
|
|
100
|
|
|
]); |
101
|
|
|
} |
102
|
|
|
|
103
|
1 |
|
private function personalDataToValidationArray(PersonalData $data, bool $skipIfValueSet = false): ?array |
104
|
|
|
{ |
105
|
1 |
|
if (false === $data->isValueFilled()) { |
106
|
1 |
|
return null; |
107
|
|
|
} |
108
|
1 |
|
if ($skipIfValueSet && $data->getValue() !== null) { |
109
|
1 |
|
return null; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return [ |
113
|
1 |
|
'name' => $data->getName(), |
114
|
1 |
|
'hash' => $data->getHash(), |
115
|
1 |
|
'challenge' => $data->getChallenge(), |
116
|
|
|
]; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.