Skip to content

Commit

Permalink
refactor: mudar organização de arquivos
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBellas committed Dec 26, 2023
1 parent bf4f7f2 commit bf13686
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 63 deletions.
2 changes: 1 addition & 1 deletion php/src/Entities/@shared/BaseEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class BaseEntity
*
* @param IBlingRepository $repository Repositório para conexão com o Bling.
*/
public function __construct(private IBlingRepository $repository)
public function __construct(protected IBlingRepository $repository)
{
}

Expand Down
28 changes: 28 additions & 0 deletions php/src/Entities/@shared/DTO/Body.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace AleBatistella\BlingErpApi\Entities\Shared\DTO;

/**
* Corpo da requisição.
*/
abstract class Body
{
/**
* Constrói o objeto.
*
* @param array<string, string|int|\DateTimeInterface> $content
*/
protected function __construct(protected array $content)
{
}

/**
* Transforma o conteúdo em _array_.
*
* @return array
*/
public function toArray(): array
{
return isset($this->content) ? $this->content : [];
}
}
28 changes: 28 additions & 0 deletions php/src/Entities/@shared/DTO/Headers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace AleBatistella\BlingErpApi\Entities\Shared\DTO;

/**
* _Headers_ da requisição.
*/
abstract class Headers
{
/**
* Constrói o objeto.
*
* @param array<string, string|int> $content
*/
protected function __construct(protected array $content)
{
}

/**
* Transforma o conteúdo em _array_.
*
* @return array
*/
public function toArray(): array
{
return isset($this->content) ? $this->content : [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@
/**
* Parâmetros da requisição (para inserção como _query parameters_).
*/
class RequestQueryParams
abstract class QueryParams
{
/**
* Constrói o objeto.
*
* @param array<string, string|int|\DateTimeInterface> $content
*/
public function __construct(public array $content)
protected function __construct(protected array $content)
{
}

/**
* Transforma o conteúdo em _array_.
*
* @return array
*/
public function toArray(): array
{
return isset($this->content) ? $this->content : [];
}
}
18 changes: 0 additions & 18 deletions php/src/Entities/@shared/DTO/RequestBody.php

This file was deleted.

18 changes: 0 additions & 18 deletions php/src/Entities/@shared/DTO/RequestHeaders.php

This file was deleted.

14 changes: 7 additions & 7 deletions php/src/Entities/@shared/DTO/RequestOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
namespace AleBatistella\BlingErpApi\Entities\Shared\DTO;

/**
* Opções para envio de uma requisição.
* Dados para envio de uma requisição.
*/
class RequestOptions
{
/**
* Constrói o objeto.
*
* @param string $endpoint
* @param ?RequestQueryParams $queryParams
* @param ?RequestHeaders $headers
* @param ?RequestBody $body
* @param ?QueryParams $queryParams
* @param ?Headers $headers
* @param ?Body $body
*/
public function __construct(
public string $endpoint,
public ?RequestQueryParams $queryParams,
public ?RequestHeaders $headers,
public ?RequestBody $body,
public ?QueryParams $queryParams = null,
public ?Headers $headers = null,
public ?Body $body = null,
) {
}
}
11 changes: 6 additions & 5 deletions php/src/Entities/@shared/DTO/ResponseOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
namespace AleBatistella\BlingErpApi\Entities\Shared\DTO;

/**
* Objeto representativo de todas os dados de resposta da requisição.
* Dados da resposta de uma requisição.
*/
class ResponseOptions
{
/**
* Constrói o objeto.
*
* @param ?RequestBody $body
* @param ?RequestHeaders $headers
* @param ?Body $body
* @param ?Headers $headers
*/
public function __construct(
public ?RequestBody $body = null,
public ?RequestHeaders $headers = [],
public int $status,
public ?Headers $headers = [],
public ?Body $body = null,
) {
}
}
39 changes: 39 additions & 0 deletions php/src/Entities/Borderos/Borderos.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,46 @@
namespace AleBatistella\BlingErpApi\Entities\Borderos;

use AleBatistella\BlingErpApi\Entities\Shared\BaseEntity;
use AleBatistella\BlingErpApi\Entities\Shared\DTO\RequestOptions;

/**
* Entidade para interação com borderôs.
*
* @see https://developer.bling.com.br/referencia#/Border%C3%B4s
*/
class Borderos extends BaseEntity
{
/**
* Remove um borderô.
*
* @param int $idBordero ID para deleção.
*
* @return null Não há retorno.
* @throws {BlingApiException|BlingInternalException}
*
* @see https://developer.bling.com.br/referencia#/Border%C3%B4s/delete_borderos__idBordero_
*/
public function delete(int $idBordero): null
{
return $this->repository->destroy(new RequestOptions(
endpoint: "borderos/$idBordero"
));
}

/**
* Encontra um borderô.
*
* @param params Parâmetros para a busca (somente o ID).
*
* @return {Promise<IFindSuccessResponse>} Os dados do borderô pesquisado.
* @throws {BlingApiException|BlingInternalException}
*
* @see https://developer.bling.com.br/referencia#/Border%C3%B4s/get_borderos__idBordero_
*/
public function find(int $idBordero)
{
return $this->repository->show(new RequestOptions(
endpoint: "borderos/$idBordero"
));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace AleBatistella\BlingErpApi\Entities\Borderos\Schema;

use AleBatistella\BlingErpApi\Entities\Shared\DTO\Body;

/**
* Corpo da resposta de busca de borderôs.
*/
class BorderoFindSuccessResponseBody extends Body
{

}
24 changes: 12 additions & 12 deletions php/src/Repositories/BlingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace AleBatistella\BlingErpApi\Repositories;

use AleBatistella\BlingErpApi\Entities\Shared\DTO\RequestBody;
use AleBatistella\BlingErpApi\Entities\Shared\DTO\RequestHeaders;
use AleBatistella\BlingErpApi\Entities\Shared\DTO\Body;
use AleBatistella\BlingErpApi\Entities\Shared\DTO\Headers;
use AleBatistella\BlingErpApi\Entities\Shared\DTO\RequestOptions;
use AleBatistella\BlingErpApi\Entities\Shared\DTO\ResponseOptions;
use GuzzleHttp\Client;
Expand Down Expand Up @@ -45,8 +45,8 @@ public function index(RequestOptions $options): ResponseOptions
$rawResponseBody = $response->getBody()->getContents();

return new ResponseOptions(
body: new RequestBody(json_decode($rawResponseBody, true)),
headers: new RequestHeaders($response->getHeaders())
body: new Body(json_decode($rawResponseBody, true)),
headers: new Headers($response->getHeaders())
);
}

Expand All @@ -72,8 +72,8 @@ public function store(RequestOptions $options): ResponseOptions
$rawResponseBody = $response->getBody()->getContents();

return new ResponseOptions(
body: new RequestBody(json_decode($rawResponseBody, true)),
headers: new RequestHeaders($response->getHeaders())
body: new Body(json_decode($rawResponseBody, true)),
headers: new Headers($response->getHeaders())
);
}

Expand All @@ -91,8 +91,8 @@ public function update(RequestOptions $options): ResponseOptions
$rawResponseBody = $response->getBody()->getContents();

return new ResponseOptions(
body: new RequestBody(json_decode($rawResponseBody, true)),
headers: new RequestHeaders($response->getHeaders())
body: new Body(json_decode($rawResponseBody, true)),
headers: new Headers($response->getHeaders())
);
}

Expand All @@ -110,8 +110,8 @@ public function replace(RequestOptions $options): ResponseOptions
$rawResponseBody = $response->getBody()->getContents();

return new ResponseOptions(
body: new RequestBody(json_decode($rawResponseBody, true)),
headers: new RequestHeaders($response->getHeaders())
body: new Body(json_decode($rawResponseBody, true)),
headers: new Headers($response->getHeaders())
);
}

Expand All @@ -129,8 +129,8 @@ public function destroy(RequestOptions $options): ResponseOptions
$rawResponseBody = $response->getBody()->getContents();

return new ResponseOptions(
body: new RequestBody(json_decode($rawResponseBody, true)),
headers: new RequestHeaders($response->getHeaders())
body: new Body(json_decode($rawResponseBody, true)),
headers: new Headers($response->getHeaders())
);
}
}

0 comments on commit bf13686

Please sign in to comment.