Skip to content

Commit 32e179e

Browse files
Correccion PHPStan-PHPUnit-php-cs-fixer para UPGRADE PHP8.5
1 parent 48ec8d8 commit 32e179e

17 files changed

Lines changed: 76 additions & 35 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111

1212
strategy:
1313
matrix:
14-
php-version: ['8.4', '8.5']
14+
php-version: ['8.5']
1515

1616
steps:
1717
- name: Check out repository code

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
},
2828
"require": {
2929
"guzzlehttp/guzzle": "^7",
30-
"php": "^8.4"
30+
"php": "^8.5"
3131
},
3232
"require-dev": {
3333
"friendsofphp/php-cs-fixer": "^3.94",
34-
"phpstan/phpstan": "^1.12",
34+
"phpstan/phpstan": "^2",
3535
"phpunit/phpunit": "^13.0",
36-
"vlucas/phpdotenv": "^5.6"
36+
"vlucas/phpdotenv": "^5.6",
37+
"phpstan/phpstan-phpunit": "^2"
3738
},
3839
"scripts": {
3940
"docs": "php tools/phpdocumentor run --config=phpdoc.xml",

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
</logging>
5656
<php>
5757
<ini name="memory_limit" value="-1" />
58-
<env name="BHEXPRESS_API_URL" value="https://bhexpress.cl" />
58+
<env name="BHEXPRESS_API_URL" value="https://app.bhexpress.cl" />
5959
<env name="BHEXPRESS_EMISOR_RUT" value="76192083-9" />
6060
</php>
6161
</phpunit>

src/ApiBase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class ApiBase extends ApiClient
3636
* @param string|null $url Versión de la API.
3737
*/
3838
public function __construct(
39-
string $token = null,
40-
string $rut = null,
41-
string $url = null
39+
?string $token = null,
40+
?string $rut = null,
41+
?string $url = null
4242
) {
4343
parent::__construct(token: $token, rut: $rut, url: $url);
4444
}

src/ApiClient.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ApiClient
3737
*
3838
* @var string
3939
*/
40-
private $api_url = 'https://bhexpress.cl';
40+
private $api_url = 'https://app.bhexpress.cl';
4141

4242
/**
4343
* El prefijo para las rutas de la API.
@@ -89,9 +89,9 @@ class ApiClient
8989
* @param string|null $url URL base de la API.
9090
*/
9191
public function __construct(
92-
string $token = null,
93-
string $rut = null,
94-
string $url = null
92+
?string $token = null,
93+
?string $rut = null,
94+
?string $url = null
9595
) {
9696
$this->api_token = $token ?: $this->env('BHEXPRESS_API_TOKEN');
9797
if (!$this->api_token) {
@@ -193,7 +193,7 @@ public function getBody(): string
193193
* @return array El cuerpo de la respuesta HTTP decodificado como un arreglo.
194194
* @throws ApiException Si no hay respuesta previa o el cuerpo no se puede decodificar.
195195
*/
196-
public function getBodyDecoded(): mixed
196+
public function getBodyDecoded(): ?array
197197
{
198198
$decodedBody = json_decode(
199199
json: $this->getBody(),
@@ -386,7 +386,7 @@ public function consume(
386386
string $resource,
387387
array $data = [],
388388
array $headers = [],
389-
string $method = null,
389+
?string $method = null,
390390
array $options = []
391391
): static {
392392
$this->last_response = null;
@@ -420,20 +420,29 @@ public function consume(
420420
$options[\GuzzleHttp\RequestOptions::JSON] = $data;
421421
}
422422

423-
// realizar consulta HTTP
423+
// Ejecutar consulta al SII.
424424
try {
425425
$this->last_response = $client->request(
426426
method: $method,
427427
uri: $this->last_url,
428428
options: $options
429429
);
430-
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
430+
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
431+
// Obtener la respuesta de la llamada.
431432
$this->last_response = $e->getResponse();
433+
434+
// Si no es un error 401 con problema de sesión se lanza la excepción.
432435
$this->throwException();
436+
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
437+
throw new ApiException('Error de conexión con el SII: ' . $e->getMessage(), 500);
433438
}
439+
440+
// Si no se reintentó se lanza excepción por no ser código 200.
434441
if ($this->getLastResponse()->getStatusCode() != 200) {
435442
$this->throwException();
436443
}
444+
445+
437446
return $this;
438447
}
439448

@@ -462,7 +471,7 @@ private function getError(): object
462471
}
463472

464473
// Se maneja el caso donde no se encuentra un mensaje de error específico
465-
if (!$message || $message === '') {
474+
if (!$message) {
466475
$message = sprintf(
467476
'[BHExpress API] Código HTTP %d: %s',
468477
$code,

src/bhe/Bhe.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class Bhe extends ApiBase
4444
* usará una URL por defecto.
4545
*/
4646
public function __construct(
47-
string $token = null,
48-
string $rut = null,
49-
string $url = null
47+
?string $token = null,
48+
?string $rut = null,
49+
?string $url = null
5050
) {
5151
parent::__construct(token: $token, rut: $rut, url: $url);
5252
}

src/bhe/Receptores.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class Receptores extends ApiBase
4444
* usará una URL por defecto.
4545
*/
4646
public function __construct(
47-
string $token = null,
48-
string $rut = null,
49-
string $url = null
47+
?string $token = null,
48+
?string $rut = null,
49+
?string $url = null
5050
) {
5151
parent::__construct(token: $token, rut: $rut, url: $url);
5252
}
@@ -77,8 +77,8 @@ public function listarReceptores(): ResponseInterface
7777
* información del receptor.
7878
*/
7979
public function obtenerDetalleReceptor(
80-
int $rut = null,
81-
int $codigo = null
80+
?int $rut = null,
81+
?int $codigo = null
8282
): ResponseInterface {
8383
$url = '/bhe/receptores';
8484

tests/bhe/boletas/AnularBheTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ public function testAnularBhe(): void
6060
$body_dec = json_decode(
6161
json: $listaBhes->getBody()->getContents(),
6262
associative: true
63-
)['results'][0];
63+
)['results'][0] ?? null;
64+
65+
if ($body_dec === null) {
66+
$this->markTestSkipped("No existen BHE emitidas");
67+
}
68+
6469
$numeroBhe = $body_dec['numero'];
6570

6671
try {

tests/bhe/boletas/DescargarPdfBheTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ public function testDescargarPdfBhe(): void
6868
$body_dec = json_decode(
6969
json: $response_body->getBody()->getContents(),
7070
associative: true
71-
)['results'][0];
71+
)['results'][0] ?? null;
72+
73+
if ($body_dec === null) {
74+
$this->markTestSkipped("No existen BHE emitidas");
75+
}
76+
7277
$numero_bhe = $body_dec['numero'];
7378

7479
try {

tests/bhe/boletas/EnviarEmailBheTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ public function testEnviarEmailBhe(): void
6666
$body_dec = json_decode(
6767
json: $listaBhes->getBody()->getContents(),
6868
associative: true
69-
)['results'][0];
69+
)['results'][0] ?? null;
70+
71+
if ($body_dec === null) {
72+
$this->markTestSkipped("No existen BHE emitidas");
73+
}
74+
7075
$numeroBhe = $body_dec['numero'];
7176

7277
try {

0 commit comments

Comments
 (0)