Skip to content

Commit

Permalink
fix: updates CepHandler class to validate both ceps at the same time …
Browse files Browse the repository at this point in the history
…and avoid duplicated origin and destiny ceps
  • Loading branch information
devaguia committed Oct 24, 2024
1 parent c74bb62 commit c24d33b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
]
},
"require-dev": {
"pestphp/pest": "^2.9",
"pestphp/pest": "^2.36.0",
"pestphp/pest-plugin-faker": "^2.0"
},
"config": {
Expand Down
Empty file removed src/Exceptions/.gitkeep
Empty file.
11 changes: 5 additions & 6 deletions src/Includes/Traits/CepHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ trait CepHandler
{
private string $originCep = '';
private string $destinyCep = '';
private function validateCep(string $cep): string
private function validateCep(string $originCep, string $destinyCep): void
{
$cleanCep = cep()->validate($cep);
$this->originCep = cep()->validate($originCep);
$this->destinyCep = cep()->validate($destinyCep);

if ($this->originCep === $cleanCep && $this->destinyCep === $cleanCep) {
throw new SameCepException($cep);
if ($this->originCep === $this->destinyCep) {
throw new SameCepException($this->originCep);
}

return $cleanCep;
}
}
3 changes: 1 addition & 2 deletions src/Services/Date/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ private function buildBody(array $serviceCodes, array $fields = []): void
public function get(array $serviceCodes, string $originCep, string $destinyCep, array $fields = []): array
{
try {
$this->originCep = $this->validateCep($originCep);
$this->destinyCep = $this->validateCep($destinyCep);
$this->validateCep($originCep, $destinyCep);

$this->buildBody($serviceCodes, $fields);
$this->sendRequest();
Expand Down
3 changes: 1 addition & 2 deletions src/Services/Price/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ private function validateProductItem(array $product): array
public function get(array $serviceCodes, array $products, string $originCep, string $destinyCep, array $fields = []): array
{
try {
$this->originCep = $this->validateCep($originCep);
$this->destinyCep = $this->validateCep($destinyCep);
$this->validateCep($originCep, $destinyCep);

$this->buildBody(
$serviceCodes,
Expand Down

0 comments on commit c24d33b

Please sign in to comment.