Skip to content

Commit

Permalink
Small refactories
Browse files Browse the repository at this point in the history
  • Loading branch information
mrprompt committed Dec 11, 2020
1 parent c6e1de5 commit 0424fd5
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 20 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"require": {
"php": "^7.4|^8",
"ext-json": "*",
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^7.2"
},
"require-dev": {
Expand Down
5 changes: 3 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
35 changes: 28 additions & 7 deletions src/Anuncios/Anuncios.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Anuncios extends Base
* @param array $args
* @return mixed
*/
public function resumo(string $imobiliaria, array $args = [])
public function resumo(string $imobiliaria, array $args = []): array
{
try {
$uri = "imobiliarias/{$imobiliaria}/anuncios/online/resumo";
Expand All @@ -23,6 +23,9 @@ public function resumo(string $imobiliaria, array $args = [])

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

Expand All @@ -33,7 +36,7 @@ public function resumo(string $imobiliaria, array $args = [])
* @param string $anuncio
* @return mixed
*/
public function remover(string $imobiliaria, string $anuncio)
public function remover(string $imobiliaria, string $anuncio): array
{
try {
$uri = "imobiliarias/{$imobiliaria}/anuncios//{$anuncio}";
Expand All @@ -42,6 +45,9 @@ public function remover(string $imobiliaria, string $anuncio)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

Expand All @@ -52,7 +58,7 @@ public function remover(string $imobiliaria, string $anuncio)
* @param string $anuncio
* @return mixed
*/
public function info(string $imobiliaria, string $anuncio)
public function info(string $imobiliaria, string $anuncio): array
{
try {
$uri = "imobiliarias/{$imobiliaria}/anuncios/{$anuncio}";
Expand All @@ -61,6 +67,9 @@ public function info(string $imobiliaria, string $anuncio)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

Expand All @@ -72,7 +81,7 @@ public function info(string $imobiliaria, string $anuncio)
* @param array $detalhes
* @return mixed
*/
public function atualizar(string $imobiliaria, string $anuncio, array $detalhes = [])
public function atualizar(string $imobiliaria, string $anuncio, array $detalhes = []): array
{
try {
$uri = "imobiliarias/{$imobiliaria}/anuncios/{$anuncio}";
Expand All @@ -82,6 +91,9 @@ public function atualizar(string $imobiliaria, string $anuncio, array $detalhes

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

Expand All @@ -93,7 +105,7 @@ public function atualizar(string $imobiliaria, string $anuncio, array $detalhes
* @param array $detalhes
* @return mixed
*/
public function associar(string $imobiliaria, string $origem, string $destino)
public function associar(string $imobiliaria, string $origem, string $destino): array
{
try {
$uri = "imobiliarias/{$imobiliaria}/anuncios/{$origem}/{$destino}";
Expand All @@ -102,6 +114,9 @@ public function associar(string $imobiliaria, string $origem, string $destino)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

Expand All @@ -112,7 +127,7 @@ public function associar(string $imobiliaria, string $origem, string $destino)
* @param string $anuncio
* @return mixed
*/
public function qualidade(string $imobiliaria, string $anuncio)
public function qualidade(string $imobiliaria, string $anuncio): array
{
try {
$uri = "imobiliarias/{$imobiliaria}/anuncios/{$anuncio}/qualidade";
Expand All @@ -121,6 +136,9 @@ public function qualidade(string $imobiliaria, string $anuncio)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

Expand All @@ -131,7 +149,7 @@ public function qualidade(string $imobiliaria, string $anuncio)
* @param string $anuncio
* @return mixed
*/
public function status(string $imobiliaria, string $anuncio)
public function status(string $imobiliaria, string $anuncio): array
{
try {
$uri = "imobiliarias/{$imobiliaria}/anuncios/{$anuncio}/status";
Expand All @@ -140,6 +158,9 @@ public function status(string $imobiliaria, string $anuncio)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}
}
9 changes: 9 additions & 0 deletions src/Anuncios/Lancamentos.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public function resumo(string $imobiliaria, string $lancamento)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

Expand All @@ -40,6 +43,9 @@ public function info(string $imobiliaria, string $lancamento)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

Expand All @@ -61,6 +67,9 @@ public function atualizar(string $imobiliaria, string $lancamento, array $detalh

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}
}
22 changes: 22 additions & 0 deletions src/Application/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

class Authentication extends Base
{
/**
* Application login
*
* @param string $clientId
* @param string $clientSecret
* @param string $grantType
* @return mixed
*/
public function login(string $clientId, string $clientSecret, string $grantType = 'client_credentials')
{
try {
Expand All @@ -23,9 +31,20 @@ public function login(string $clientId, string $clientSecret, string $grantType

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

/**
* Logout de usuario
*
* @param string $clientId
* @param string $clientSecret
* @param string $token
* @return mixed
*/
public function logout(string $clientId, string $clientSecret, string $token)
{
try {
Expand All @@ -43,6 +62,9 @@ public function logout(string $clientId, string $clientSecret, string $token)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}
}
8 changes: 6 additions & 2 deletions src/Configuracao/Callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public function listar()

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
return [];
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

Expand All @@ -36,7 +38,9 @@ public function atualizar(array $configuracoes)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
return [];
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}
}
16 changes: 12 additions & 4 deletions src/Imobiliarias/Imobiliarias.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public function listar()

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
return [];
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

Expand All @@ -35,7 +37,9 @@ public function desvincular(string $imobiliaria)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
return [];
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

Expand All @@ -52,7 +56,9 @@ public function ftp(string $imobiliaria)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
return [];
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

Expand All @@ -69,7 +75,9 @@ public function qualidade(string $imobiliaria)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
return [];
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}
}
8 changes: 6 additions & 2 deletions src/Vendas/Vendas.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public function disponibilidade(string $imobiliaria)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
return [];
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}

Expand All @@ -36,7 +38,9 @@ public function grade(string $imobiliaria)

return json_decode($response->getBody(), true);
} catch (ClientException $clientException) {
return [];
$xml = simplexml_load_string($clientException->getResponse()->getBody());

return json_decode(json_encode($xml), true);
}
}
}
8 changes: 5 additions & 3 deletions tests/Application/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ public function loginWithInvalidCredentials()
$this->faker->randomNumber(6)
);

$this->assertEmpty($result);
$this->assertArrayHasKey('error', $result);
$this->assertArrayHasKey('error_description', $result);
}

/**
* @test
*/
public function logoutWithValidCredentials()
{
$handleResponse = '';
$handleResponse = $this->fixture(__FUNCTION__, 'Responses');
$handlerStack = [new Response(204, [], $handleResponse)];

$this->client = $this->getClient($handlerStack);
Expand Down Expand Up @@ -85,6 +86,7 @@ public function logoutWithoutClientId()
$this->faker->uuid,
);

$this->assertEmpty($result);
$this->assertArrayHasKey('error', $result);
$this->assertArrayHasKey('error_description', $result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit 0424fd5

Please sign in to comment.