Passed
Push — master ( a09b08...043816 )
by Luiz Kim
02:35
created
src/Service/AddressService.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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(Street::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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.