@@ -45,14 +45,17 @@ discard block |
||
45 | 45 | public function discoveryPeople(?string $document = null, ?string $email = null, ?array $phone = [], ?string $name = null, ?string $peopleType = null): People |
46 | 46 | { |
47 | 47 | |
48 | - if (!empty($document)) |
|
49 | - $people = $this->getDocument($document)?->getPeople(); |
|
48 | + if (!empty($document)) { |
|
49 | + $people = $this->getDocument($document)?->getPeople(); |
|
50 | + } |
|
50 | 51 | |
51 | - if (!$people && !empty($email)) |
|
52 | - $people = $this->getEmail($email)?->getPeople(); |
|
52 | + if (!$people && !empty($email)) { |
|
53 | + $people = $this->getEmail($email)?->getPeople(); |
|
54 | + } |
|
53 | 55 | |
54 | - if (!$people && !empty($phone)) |
|
55 | - $people = $this->getPhone($phone['ddd'], $phone['phone'])?->getPeople(); |
|
56 | + if (!$people && !empty($phone)) { |
|
57 | + $people = $this->getPhone($phone['ddd'], $phone['phone'])?->getPeople(); |
|
58 | + } |
|
56 | 59 | |
57 | 60 | if (!$people) { |
58 | 61 | $people = new People(); |
@@ -63,12 +66,15 @@ discard block |
||
63 | 66 | $this->manager->flush(); |
64 | 67 | } |
65 | 68 | |
66 | - if ($document) |
|
67 | - $this->addDocument($people, $document); |
|
68 | - if ($email) |
|
69 | - $this->addEmail($people, $email); |
|
70 | - if ($phone) |
|
71 | - $this->addPhone($people, $phone); |
|
69 | + if ($document) { |
|
70 | + $this->addDocument($people, $document); |
|
71 | + } |
|
72 | + if ($email) { |
|
73 | + $this->addEmail($people, $email); |
|
74 | + } |
|
75 | + if ($phone) { |
|
76 | + $this->addPhone($people, $phone); |
|
77 | + } |
|
72 | 78 | |
73 | 79 | |
74 | 80 | return $people; |
@@ -78,8 +84,9 @@ discard block |
||
78 | 84 | { |
79 | 85 | $phone = $this->getPhone($phone_number['ddd'], $phone_number['phone']); |
80 | 86 | if ($phone && $phone->getPeople()) { |
81 | - if ($phone->getPeople()->getId() != $people->getId()) |
|
82 | - throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
87 | + if ($phone->getPeople()->getId() != $people->getId()) { |
|
88 | + throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
89 | + } |
|
83 | 90 | } else { |
84 | 91 | $phone = new Phone(); |
85 | 92 | $phone->setDdd($phone_number['ddd']); |
@@ -95,8 +102,9 @@ discard block |
||
95 | 102 | { |
96 | 103 | $document = $this->getDocument($document_number, $document_type); |
97 | 104 | if ($document) { |
98 | - if ($document->getPeople()->getId() != $people->getId()) |
|
99 | - throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
105 | + if ($document->getPeople()->getId() != $people->getId()) { |
|
106 | + throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
107 | + } |
|
100 | 108 | } else { |
101 | 109 | $document = new Document(); |
102 | 110 | $document->setDocument($document_number); |
@@ -113,8 +121,9 @@ discard block |
||
113 | 121 | { |
114 | 122 | $email = $this->getEmail($email_str); |
115 | 123 | if ($email && $email->getPeople()) { |
116 | - if ($email->getPeople()->getId() != $people->getId()) |
|
117 | - throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
124 | + if ($email->getPeople()->getId() != $people->getId()) { |
|
125 | + throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
126 | + } |
|
118 | 127 | } else { |
119 | 128 | $email = new Email(); |
120 | 129 | $email->setEmail($email_str); |
@@ -153,8 +162,9 @@ discard block |
||
153 | 162 | |
154 | 163 | public function getDocument(string $document_number, ?string $document_type = null): ?Document |
155 | 164 | { |
156 | - if (!$document_type) |
|
157 | - $document_type = $this->getDocumentTypeByDocumentLen($document_number); |
|
165 | + if (!$document_type) { |
|
166 | + $document_type = $this->getDocumentTypeByDocumentLen($document_number); |
|
167 | + } |
|
158 | 168 | return $this->manager->getRepository(Document::class)->findOneBy([ |
159 | 169 | 'document' => $document_number, |
160 | 170 | 'documentType' => |
@@ -175,18 +185,21 @@ discard block |
||
175 | 185 | public function postPersist(People $people) |
176 | 186 | { |
177 | 187 | $request = $this->requestStack->getCurrentRequest(); |
178 | - if (!$request) return; |
|
188 | + if (!$request) { |
|
189 | + return; |
|
190 | + } |
|
179 | 191 | $payload = json_decode($request->getContent()); |
180 | 192 | if (isset($payload->link_type)) { |
181 | 193 | $company = $this->manager->getRepository(People::class)->find(preg_replace('/\D/', '', $payload->company)); |
182 | - if ($company) |
|
183 | - $this->addLink($company, $people, $payload->link_type); |
|
184 | - else { |
|
194 | + if ($company) { |
|
195 | + $this->addLink($company, $people, $payload->link_type); |
|
196 | + } else { |
|
185 | 197 | $link = $this->manager->getRepository(People::class)->find(preg_replace('/\D/', '', $payload->link)); |
186 | 198 | if ($payload->link_type == 'employee' && $link) { |
187 | 199 | $this->addLink($people, $link, $payload->link_type); |
188 | - if ($payload->people_document) |
|
189 | - $this->addDocument($people, $payload->people_document); |
|
200 | + if ($payload->people_document) { |
|
201 | + $this->addDocument($people, $payload->people_document); |
|
202 | + } |
|
190 | 203 | } |
191 | 204 | } |
192 | 205 | } |
@@ -201,8 +214,9 @@ discard block |
||
201 | 214 | 'link_type' => $link_type |
202 | 215 | ]); |
203 | 216 | |
204 | - if (!$peopleLink) |
|
205 | - $peopleLink = new PeopleLink(); |
|
217 | + if (!$peopleLink) { |
|
218 | + $peopleLink = new PeopleLink(); |
|
219 | + } |
|
206 | 220 | |
207 | 221 | $peopleLink->setCompany($company); |
208 | 222 | $peopleLink->setPeople($people); |
@@ -254,10 +268,14 @@ discard block |
||
254 | 268 | * @var \ControleOnline\Entity\User $currentUser |
255 | 269 | */ |
256 | 270 | $token = $this->security->getToken(); |
257 | - if (!$token) return []; |
|
271 | + if (!$token) { |
|
272 | + return []; |
|
273 | + } |
|
258 | 274 | $currentUser = $token->getUser(); |
259 | 275 | $companies = []; |
260 | - if (!$currentUser) return []; |
|
276 | + if (!$currentUser) { |
|
277 | + return []; |
|
278 | + } |
|
261 | 279 | |
262 | 280 | if (!$currentUser->getPeople()->getLink()->isEmpty()) { |
263 | 281 | foreach ($currentUser->getPeople()->getLink() as $company) { |