@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $district = ($district && $city) ? $this->discoveryDistrict($city, $district) : null; |
45 | 45 | $street = ($streetName && $cep && $district) ? $this->discoveryStreet($cep, $district, $streetName) : null; |
46 | 46 | |
47 | - $address = $this->manager->getRepository(Address::class)->findOneBy([ |
|
47 | + $address = $this->manager->getRepository(Address::class)->findOneBy([ |
|
48 | 48 | 'people' => $people, |
49 | 49 | 'street' => $street, |
50 | 50 | 'number' => $streetNumber, |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | 'district' => $district, |
92 | 92 | 'street' => $streetName |
93 | 93 | ]; |
94 | - $street = $this->manager->getRepository(Street::class)->findOneBy($search); |
|
94 | + $street = $this->manager->getRepository(Street::class)->findOneBy($search); |
|
95 | 95 | |
96 | 96 | if (!$street) { |
97 | 97 | $street = new Street(); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | |
113 | 113 | $search['district'] = $districtName; |
114 | 114 | |
115 | - $district = $this->manager->getRepository(District::class)->findOneBy($search); |
|
115 | + $district = $this->manager->getRepository(District::class)->findOneBy($search); |
|
116 | 116 | |
117 | 117 | if (!$district) { |
118 | 118 | $district = new District(); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | if ($cod_ibge) |
137 | 137 | $search['cod_ibge'] = $cod_ibge; |
138 | 138 | |
139 | - $city = $this->manager->getRepository(City::class)->findOneBy($search); |
|
139 | + $city = $this->manager->getRepository(City::class)->findOneBy($search); |
|
140 | 140 | |
141 | 141 | if (!$city) { |
142 | 142 | $city = new City(); |
@@ -59,8 +59,12 @@ discard block |
||
59 | 59 | $address->setStreet($street); |
60 | 60 | $address->setPeople($people); |
61 | 61 | } |
62 | - if ($latitude > 0) $address->setLatitude($latitude); |
|
63 | - if ($longitude > 0) $address->setLongitude($longitude); |
|
62 | + if ($latitude > 0) { |
|
63 | + $address->setLatitude($latitude); |
|
64 | + } |
|
65 | + if ($longitude > 0) { |
|
66 | + $address->setLongitude($longitude); |
|
67 | + } |
|
64 | 68 | |
65 | 69 | |
66 | 70 | $this->manager->persist($address); |
@@ -125,16 +129,19 @@ discard block |
||
125 | 129 | } |
126 | 130 | public function discoveryCity(State $state, ?string $cityName = null, ?string $cod_ibge = null): City |
127 | 131 | { |
128 | - if (!$cityName && !$cod_ibge) |
|
129 | - throw new Exception("Need a param to search city", 404); |
|
132 | + if (!$cityName && !$cod_ibge) { |
|
133 | + throw new Exception("Need a param to search city", 404); |
|
134 | + } |
|
130 | 135 | |
131 | 136 | $search = [ |
132 | 137 | 'state' => $state |
133 | 138 | ]; |
134 | - if ($state) |
|
135 | - $search['city'] = $cityName; |
|
136 | - if ($cod_ibge) |
|
137 | - $search['cod_ibge'] = $cod_ibge; |
|
139 | + if ($state) { |
|
140 | + $search['city'] = $cityName; |
|
141 | + } |
|
142 | + if ($cod_ibge) { |
|
143 | + $search['cod_ibge'] = $cod_ibge; |
|
144 | + } |
|
138 | 145 | |
139 | 146 | $city = $this->manager->getRepository(City::class)->findOneBy($search); |
140 | 147 | |
@@ -150,18 +157,22 @@ discard block |
||
150 | 157 | } |
151 | 158 | public function discoveryState(Country $country, ?string $uf = null, ?string $stateName = null, ?string $cod_ibge = null): State |
152 | 159 | { |
153 | - if (!$uf && !$stateName && !$cod_ibge) |
|
154 | - throw new Exception("Need a param to search state", 404); |
|
160 | + if (!$uf && !$stateName && !$cod_ibge) { |
|
161 | + throw new Exception("Need a param to search state", 404); |
|
162 | + } |
|
155 | 163 | |
156 | 164 | $search = [ |
157 | 165 | 'country' => $country |
158 | 166 | ]; |
159 | - if ($stateName) |
|
160 | - $search['state'] = $stateName; |
|
161 | - if ($cod_ibge) |
|
162 | - $search['cod_ibge'] = $cod_ibge; |
|
163 | - if ($uf) |
|
164 | - $search['uf'] = $uf; |
|
167 | + if ($stateName) { |
|
168 | + $search['state'] = $stateName; |
|
169 | + } |
|
170 | + if ($cod_ibge) { |
|
171 | + $search['cod_ibge'] = $cod_ibge; |
|
172 | + } |
|
173 | + if ($uf) { |
|
174 | + $search['uf'] = $uf; |
|
175 | + } |
|
165 | 176 | |
166 | 177 | $state = $this->manager->getRepository(State::class)->findOneBy($search); |
167 | 178 |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - public function __construct( |
|
21 | + public function __construct( |
|
22 | 22 | private EntityManagerInterface $manager |
23 | - ) {} |
|
23 | + ) {} |
|
24 | 24 | |
25 | - public function discoveryAddress( |
|
25 | + public function discoveryAddress( |
|
26 | 26 | ?People $people = null, |
27 | 27 | int $postalCode, |
28 | 28 | int $streetNumber, |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | ?int $latitude = 0, |
36 | 36 | ?int $longitude = 0, |
37 | 37 | ?string $nickName = 'Default', |
38 | - ): Address { |
|
38 | + ): Address { |
|
39 | 39 | |
40 | 40 | $cep = ($postalCode) ? $this->discoveryCep($postalCode) : null; |
41 | 41 | $country = ($countryCode) ? $this->getCountry($countryCode) : null; |
@@ -45,19 +45,19 @@ discard block |
||
45 | 45 | $street = ($streetName && $cep && $district) ? $this->discoveryStreet($cep, $district, $streetName) : null; |
46 | 46 | |
47 | 47 | $address = $this->manager->getRepository(Address::class)->findOneBy([ |
48 | - 'people' => $people, |
|
49 | - 'street' => $street, |
|
50 | - 'number' => $streetNumber, |
|
51 | - 'complement' => $complement |
|
48 | + 'people' => $people, |
|
49 | + 'street' => $street, |
|
50 | + 'number' => $streetNumber, |
|
51 | + 'complement' => $complement |
|
52 | 52 | ]); |
53 | 53 | |
54 | 54 | if (!$address) { |
55 | - $address = new Address(); |
|
56 | - $address->setNumber($streetNumber); |
|
57 | - $address->setNickname($nickName); |
|
58 | - $address->setComplement($complement); |
|
59 | - $address->setStreet($street); |
|
60 | - $address->setPeople($people); |
|
55 | + $address = new Address(); |
|
56 | + $address->setNumber($streetNumber); |
|
57 | + $address->setNickname($nickName); |
|
58 | + $address->setComplement($complement); |
|
59 | + $address->setStreet($street); |
|
60 | + $address->setPeople($people); |
|
61 | 61 | } |
62 | 62 | if ($latitude > 0) $address->setLatitude($latitude); |
63 | 63 | if ($longitude > 0) $address->setLongitude($longitude); |
@@ -67,47 +67,47 @@ discard block |
||
67 | 67 | $this->manager->flush(); |
68 | 68 | |
69 | 69 | return $address; |
70 | - } |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | 73 | |
74 | - public function discoveryCep(string $postalCode): Cep |
|
75 | - { |
|
74 | + public function discoveryCep(string $postalCode): Cep |
|
75 | + { |
|
76 | 76 | $cep = $this->manager->getRepository(Cep::class)->findOneBy(['cep' => $postalCode]); |
77 | 77 | |
78 | 78 | if (!$cep) { |
79 | - $cep = new Cep(); |
|
80 | - $cep->setCep($postalCode); |
|
81 | - $this->manager->persist($cep); |
|
82 | - $this->manager->flush(); |
|
79 | + $cep = new Cep(); |
|
80 | + $cep->setCep($postalCode); |
|
81 | + $this->manager->persist($cep); |
|
82 | + $this->manager->flush(); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | return $cep; |
86 | - } |
|
87 | - public function discoveryStreet(Cep $cep, District $district, string $streetName): Street |
|
88 | - { |
|
86 | + } |
|
87 | + public function discoveryStreet(Cep $cep, District $district, string $streetName): Street |
|
88 | + { |
|
89 | 89 | $search = [ |
90 | - 'cep' => $cep, |
|
91 | - 'district' => $district, |
|
92 | - 'street' => $streetName |
|
90 | + 'cep' => $cep, |
|
91 | + 'district' => $district, |
|
92 | + 'street' => $streetName |
|
93 | 93 | ]; |
94 | 94 | $street = $this->manager->getRepository(Street::class)->findOneBy($search); |
95 | 95 | |
96 | 96 | if (!$street) { |
97 | - $street = new Street(); |
|
98 | - $street->setCep($cep); |
|
99 | - $street->setDistrict($district); |
|
100 | - $street->setStreet($streetName); |
|
101 | - $this->manager->persist($street); |
|
102 | - $this->manager->flush(); |
|
97 | + $street = new Street(); |
|
98 | + $street->setCep($cep); |
|
99 | + $street->setDistrict($district); |
|
100 | + $street->setStreet($streetName); |
|
101 | + $this->manager->persist($street); |
|
102 | + $this->manager->flush(); |
|
103 | 103 | } |
104 | 104 | return $street; |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | - public function discoveryDistrict(City $city, string $districtName): District |
|
108 | - { |
|
107 | + public function discoveryDistrict(City $city, string $districtName): District |
|
108 | + { |
|
109 | 109 | $search = [ |
110 | - 'city' => $city |
|
110 | + 'city' => $city |
|
111 | 111 | ]; |
112 | 112 | |
113 | 113 | $search['district'] = $districtName; |
@@ -115,71 +115,71 @@ discard block |
||
115 | 115 | $district = $this->manager->getRepository(District::class)->findOneBy($search); |
116 | 116 | |
117 | 117 | if (!$district) { |
118 | - $district = new District(); |
|
119 | - $district->setCity($city); |
|
120 | - $district->setDistrict($districtName); |
|
121 | - $this->manager->persist($district); |
|
122 | - $this->manager->flush(); |
|
118 | + $district = new District(); |
|
119 | + $district->setCity($city); |
|
120 | + $district->setDistrict($districtName); |
|
121 | + $this->manager->persist($district); |
|
122 | + $this->manager->flush(); |
|
123 | 123 | } |
124 | 124 | return $district; |
125 | - } |
|
126 | - public function discoveryCity(State $state, ?string $cityName = null, ?string $cod_ibge = null): City |
|
127 | - { |
|
125 | + } |
|
126 | + public function discoveryCity(State $state, ?string $cityName = null, ?string $cod_ibge = null): City |
|
127 | + { |
|
128 | 128 | if (!$cityName && !$cod_ibge) |
129 | - throw new Exception("Need a param to search city", 404); |
|
129 | + throw new Exception("Need a param to search city", 404); |
|
130 | 130 | |
131 | 131 | $search = [ |
132 | - 'state' => $state |
|
132 | + 'state' => $state |
|
133 | 133 | ]; |
134 | 134 | if ($state) |
135 | - $search['city'] = $cityName; |
|
135 | + $search['city'] = $cityName; |
|
136 | 136 | if ($cod_ibge) |
137 | - $search['cod_ibge'] = $cod_ibge; |
|
137 | + $search['cod_ibge'] = $cod_ibge; |
|
138 | 138 | |
139 | 139 | $city = $this->manager->getRepository(City::class)->findOneBy($search); |
140 | 140 | |
141 | 141 | if (!$city) { |
142 | - $city = new City(); |
|
143 | - $city->setCity($cityName); |
|
144 | - $city->setState($state); |
|
145 | - $city->setIbge($cod_ibge); |
|
146 | - $this->manager->persist($city); |
|
147 | - $this->manager->flush(); |
|
142 | + $city = new City(); |
|
143 | + $city->setCity($cityName); |
|
144 | + $city->setState($state); |
|
145 | + $city->setIbge($cod_ibge); |
|
146 | + $this->manager->persist($city); |
|
147 | + $this->manager->flush(); |
|
148 | 148 | } |
149 | 149 | return $city; |
150 | - } |
|
151 | - public function discoveryState(Country $country, ?string $uf = null, ?string $stateName = null, ?string $cod_ibge = null): State |
|
152 | - { |
|
150 | + } |
|
151 | + public function discoveryState(Country $country, ?string $uf = null, ?string $stateName = null, ?string $cod_ibge = null): State |
|
152 | + { |
|
153 | 153 | if (!$uf && !$stateName && !$cod_ibge) |
154 | - throw new Exception("Need a param to search state", 404); |
|
154 | + throw new Exception("Need a param to search state", 404); |
|
155 | 155 | |
156 | 156 | $search = [ |
157 | - 'country' => $country |
|
157 | + 'country' => $country |
|
158 | 158 | ]; |
159 | 159 | if ($stateName) |
160 | - $search['state'] = $stateName; |
|
160 | + $search['state'] = $stateName; |
|
161 | 161 | if ($cod_ibge) |
162 | - $search['cod_ibge'] = $cod_ibge; |
|
162 | + $search['cod_ibge'] = $cod_ibge; |
|
163 | 163 | if ($uf) |
164 | - $search['uf'] = $uf; |
|
164 | + $search['uf'] = $uf; |
|
165 | 165 | |
166 | 166 | $state = $this->manager->getRepository(State::class)->findOneBy($search); |
167 | 167 | |
168 | 168 | |
169 | 169 | if (!$state) { |
170 | - $state = new State(); |
|
171 | - $state->setState($stateName); |
|
172 | - $state->setIbge($cod_ibge); |
|
173 | - $state->setUf($uf); |
|
174 | - $state->setCountry($country); |
|
175 | - $this->manager->persist($state); |
|
176 | - $this->manager->flush(); |
|
170 | + $state = new State(); |
|
171 | + $state->setState($stateName); |
|
172 | + $state->setIbge($cod_ibge); |
|
173 | + $state->setUf($uf); |
|
174 | + $state->setCountry($country); |
|
175 | + $this->manager->persist($state); |
|
176 | + $this->manager->flush(); |
|
177 | 177 | } |
178 | 178 | return $state; |
179 | - } |
|
179 | + } |
|
180 | 180 | |
181 | - public function getCountry(string $countryCode): Country |
|
182 | - { |
|
181 | + public function getCountry(string $countryCode): Country |
|
182 | + { |
|
183 | 183 | return $this->manager->getRepository(Country::class)->findOneBy(['countrycode' => $countryCode]); |
184 | - } |
|
184 | + } |
|
185 | 185 | } |
@@ -17,8 +17,9 @@ |
||
17 | 17 | |
18 | 18 | public function discoveryBotUser(): void |
19 | 19 | { |
20 | - if (!self::$botUser) |
|
21 | - $bots = ['R2D2', 'C3PO', 'T800', 'SkyNet']; |
|
20 | + if (!self::$botUser) { |
|
21 | + $bots = ['R2D2', 'C3PO', 'T800', 'SkyNet']; |
|
22 | + } |
|
22 | 23 | |
23 | 24 | $online = array_rand($bots); |
24 | 25 | $bot = $bots[$online]; |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | |
46 | - public function discoveryExtraData(int|string $entityId, ExtraFields $extraFields, string $code, object | string $entity) |
|
46 | + public function discoveryExtraData(int | string $entityId, ExtraFields $extraFields, string $code, object | string $entity) |
|
47 | 47 | { |
48 | 48 | $class = $this->getEntityName($entity); |
49 | 49 | |
50 | - $extraData = $this->getEntityByExtraData($extraFields, $entityId, $entity, $code); |
|
50 | + $extraData = $this->getEntityByExtraData($extraFields, $entityId, $entity, $code); |
|
51 | 51 | if ($extraData) return $extraData; |
52 | 52 | |
53 | 53 | $extraData = new ExtraData(); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | return $this->manager->getRepository($class->getName())->find($extraData->getEntityId()); |
62 | 62 | } |
63 | 63 | |
64 | - public function discoveryExtraFields(string $fieldName, string $context, ?string $configs = '{}', ?string $fieldType = 'text', ?bool $required = false): ExtraFields |
|
64 | + public function discoveryExtraFields(string $fieldName, string $context, ?string $configs = '{}', ?string $fieldType = 'text', ?bool $required = false): ExtraFields |
|
65 | 65 | { |
66 | 66 | |
67 | 67 | $extraFields = $this->manager->getRepository(ExtraFields::class)->findOneBy([ |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | |
138 | 138 | //$this->manager->persist($entity); |
139 | 139 | } else { |
140 | - $json = json_decode($this->request->getContent(), true); |
|
140 | + $json = json_decode($this->request->getContent(), true); |
|
141 | 141 | $extra_data = isset($json['extra-data']) ? $json['extra-data'] : null; |
142 | 142 | if (!$extra_data) |
143 | 143 | return; |
@@ -36,8 +36,9 @@ discard block |
||
36 | 36 | 'entity_id' => $entityId, |
37 | 37 | 'value' => $code |
38 | 38 | ]); |
39 | - if ($extraData) |
|
40 | - return $this->manager->getRepository($class->getName())->find($extraData->getEntityId()); |
|
39 | + if ($extraData) { |
|
40 | + return $this->manager->getRepository($class->getName())->find($extraData->getEntityId()); |
|
41 | + } |
|
41 | 42 | |
42 | 43 | return null; |
43 | 44 | } |
@@ -48,7 +49,9 @@ discard block |
||
48 | 49 | $class = $this->getEntityName($entity); |
49 | 50 | |
50 | 51 | $extraData = $this->getEntityByExtraData($extraFields, $entityId, $entity, $code); |
51 | - if ($extraData) return $extraData; |
|
52 | + if ($extraData) { |
|
53 | + return $extraData; |
|
54 | + } |
|
52 | 55 | |
53 | 56 | $extraData = new ExtraData(); |
54 | 57 | $extraData->setEntityId($entityId); |
@@ -92,12 +95,15 @@ discard block |
||
92 | 95 | |
93 | 96 | public function discoveryDevice(&$entity) |
94 | 97 | { |
95 | - if ($entity instanceof Device || $entity instanceof DeviceConfig || !$this->request->headers) |
|
96 | - return; |
|
98 | + if ($entity instanceof Device || $entity instanceof DeviceConfig || !$this->request->headers) { |
|
99 | + return; |
|
100 | + } |
|
97 | 101 | |
98 | 102 | $deviceId = $this->request->headers->get('DEVICE') ?: $this->getUserIp(); |
99 | 103 | if (method_exists($entity, 'setDevice')) { |
100 | - if ($entity->getDevice()) return; |
|
104 | + if ($entity->getDevice()) { |
|
105 | + return; |
|
106 | + } |
|
101 | 107 | $device = $this->deviceService->discoveryDevice($deviceId); |
102 | 108 | $entity->setDevice($device); |
103 | 109 | } |
@@ -108,14 +114,16 @@ discard block |
||
108 | 114 | $token = $this->security->getToken(); |
109 | 115 | $user = $token ? $token->getUser() : $this->skyNetService->getBotUser(); |
110 | 116 | |
111 | - if (method_exists($entity, 'setUser') && !$entity->getUser()) |
|
112 | - $entity->setUser($user); |
|
117 | + if (method_exists($entity, 'setUser') && !$entity->getUser()) { |
|
118 | + $entity->setUser($user); |
|
119 | + } |
|
113 | 120 | } |
114 | 121 | |
115 | 122 | public function persist(&$entity) |
116 | 123 | { |
117 | - if (self::$persisted == true) |
|
118 | - return; |
|
124 | + if (self::$persisted == true) { |
|
125 | + return; |
|
126 | + } |
|
119 | 127 | self::$persisted = true; |
120 | 128 | |
121 | 129 | //$this->manager->persist($entity); |
@@ -139,15 +147,17 @@ discard block |
||
139 | 147 | } else { |
140 | 148 | $json = json_decode($this->request->getContent(), true); |
141 | 149 | $extra_data = isset($json['extra-data']) ? $json['extra-data'] : null; |
142 | - if (!$extra_data) |
|
143 | - return; |
|
150 | + if (!$extra_data) { |
|
151 | + return; |
|
152 | + } |
|
144 | 153 | $entity_id = $extra_data['entity_id']; |
145 | 154 | $entity_name = $extra_data['entity_name']; |
146 | 155 | } |
147 | 156 | |
148 | 157 | |
149 | - if (!$entity_id || !$entity_name) |
|
150 | - return; |
|
158 | + if (!$entity_id || !$entity_name) { |
|
159 | + return; |
|
160 | + } |
|
151 | 161 | |
152 | 162 | foreach ($extra_data['data'] as $key => $data) { |
153 | 163 | $extra_fields = $this->manager->getRepository(ExtraFields::class)->find($key); |
@@ -158,8 +168,9 @@ discard block |
||
158 | 168 | 'extra_fields' => $extra_fields |
159 | 169 | ]); |
160 | 170 | |
161 | - if (!$extraData) |
|
162 | - $extraData = new ExtraData(); |
|
171 | + if (!$extraData) { |
|
172 | + $extraData = new ExtraData(); |
|
173 | + } |
|
163 | 174 | |
164 | 175 | $extraData->setExtraFields($extra_fields); |
165 | 176 | $extraData->setEntityName($entity_name); |