diff --git a/.gitattributes b/.gitattributes
index d1943ad..3162563 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -18,10 +18,10 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
-/.scrutinizer.yml export-ignore
/phpcs.xml.dist export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
+sonar-project.properties export-ignore
# Do not count these files on github code language
/tests/_files/** linguist-detectable=false
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 818f3a2..096776c 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -22,13 +22,13 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: '8.3'
+ php-version: '8.4'
coverage: none
tools: composer-normalize
env:
fail-fast: true
- name: Composer normalize
- run: composer-normalize
+ run: composer-normalize --dry-run
phpcs:
name: Code style (phpcs)
@@ -39,7 +39,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: '8.3'
+ php-version: '8.4'
coverage: none
tools: cs2pr, phpcs
env:
@@ -56,7 +56,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: '8.3'
+ php-version: '8.4'
coverage: none
tools: cs2pr, php-cs-fixer
env:
@@ -73,7 +73,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: '8.3'
+ php-version: '8.4'
coverage: none
tools: composer:v2, phpstan
extensions: soap
@@ -98,7 +98,7 @@ jobs:
runs-on: "ubuntu-latest"
strategy:
matrix:
- php-version: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
+ php-version: ['8.1', '8.2', '8.3', '8.4']
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -123,4 +123,4 @@ jobs:
- name: Install project dependencies
run: composer upgrade --no-interaction --no-progress --prefer-dist
- name: Tests (phpunit)
- run: vendor/bin/phpunit tests/Unit/ --testdox --verbose
+ run: vendor/bin/phpunit tests/Unit/ --testdox
diff --git a/.github/workflows/functional-tests.yml b/.github/workflows/sonarqube-cloud.yml
similarity index 55%
rename from .github/workflows/functional-tests.yml
rename to .github/workflows/sonarqube-cloud.yml
index e2b9b25..bf60b9d 100644
--- a/.github/workflows/functional-tests.yml
+++ b/.github/workflows/sonarqube-cloud.yml
@@ -1,68 +1,72 @@
-name: functional-tests
+name: "SonarQube Cloud"
on:
# secrets are not passed to workflows that are triggered by a pull request from a fork.
# see https://docs.github.com/en/actions/reference/encrypted-secrets
workflow_dispatch:
push:
- branches: [ 'main' ]
+ branches: [ "main" ]
# Actions
# shivammathur/setup-php@v2 https://github.com/marketplace/actions/setup-php-action
-# sudo-bot/action-scrutinizer@latest https://github.com/marketplace/actions/action-scrutinizer
+# SonarSource/sonarqube-scan-action@v6 https://github.com/marketplace/actions/official-sonarqube-scan
jobs:
- functional-tests:
- name: Functional tests
- runs-on: "ubuntu-latest"
+ sonarqube-cloud:
+ name: SonarCloud Scan and Report
+ runs-on: "ubuntu-latest"
steps:
-
+ - name: Check SONAR_TOKEN secret
+ run: |
+ if [ -z "${{ secrets.SONAR_TOKEN }}" ]; then
+ echo "::warning ::SONAR_TOKEN non set"
+ exit 1
+ fi
+ - name: Check ENV_GPG_SECRET secret
+ run: |
+ if [ -z "${{ secrets.ENV_GPG_SECRET }}" ]; then
+ echo "::warning ::ENV_GPG_SECRET non set"
+ exit 1
+ fi
- name: Checkout
uses: actions/checkout@v4
- with:
- fetch-depth: 0 # required for sudo-bot/action-scrutinizer
-
+ - name: Unshallow clone to provide blame information
+ run: git fetch --unshallow
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: '8.3'
+ php-version: '8.4'
extensions: soap
coverage: xdebug
tools: composer:v2
- env:
- fail-fast: true
-
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
-
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
-
- name: Install project dependencies
run: composer upgrade --no-interaction --no-progress --prefer-dist
-
- name: Install SAT XML resources
shell: bash
run: |
git clone --depth 1 https://github.com/phpcfdi/resources-sat-xml resources-sat-xml-cloned
mv resources-sat-xml-cloned/resources vendor/eclipxe/cfdiutils/build/resources
rm -r -f resources-sat-xml-cloned
-
- name: Set up environment file
run: gpg --quiet --batch --yes --decrypt --passphrase="$ENV_GPG_SECRET" --output tests/.env tests/.env-testing.enc
env:
ENV_GPG_SECRET: ${{ secrets.ENV_GPG_SECRET }}
-
- - name: Run integration tests with code coverage
- run: vendor/bin/phpunit --testdox --verbose --exclude-group large --coverage-clover=build/coverage-clover.xml
-
- - name: Upload code coverage to scrutinizer
- uses: sudo-bot/action-scrutinizer@latest
- with:
- cli-args: "--format=php-clover build/coverage-clover.xml"
- continue-on-error: true
+ - name: Create code coverage
+ run: vendor/bin/phpunit --coverage-xml=build/coverage --coverage-clover=build/coverage/clover.xml --log-junit=build/coverage/junit.xml
+ - name: Prepare SonarCloud Code Coverage Files
+ run: |
+ sed 's#'$GITHUB_WORKSPACE'#/github/workspace#g' build/coverage/junit.xml > build/sonar-junit.xml
+ sed 's#'$GITHUB_WORKSPACE'#/github/workspace#g' build/coverage/clover.xml > build/sonar-coverage.xml
+ - name: SonarCloud Scan
+ uses: SonarSource/sonarqube-scan-action@v6
+ env:
+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
diff --git a/.phive/phars.xml b/.phive/phars.xml
index 0028181..89ef54c 100644
--- a/.phive/phars.xml
+++ b/.phive/phars.xml
@@ -1,8 +1,8 @@
-
-
-
-
-
+
+
+
+
+
diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
index 2b6cddb..7d1c30e 100644
--- a/.php-cs-fixer.dist.php
+++ b/.php-cs-fixer.dist.php
@@ -15,15 +15,16 @@
->setRules([
'@PSR12' => true,
'@PSR12:risky' => true,
- '@PHP71Migration:risky' => true,
- '@PHP73Migration' => true,
+ '@PHP8x1Migration' => true,
+ '@PHP8x0Migration:risky' => true,
// symfony
+ 'array_indentation' => true,
'class_attributes_separation' => true,
'whitespace_after_comma_in_array' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'type_declaration_spaces' => true,
- 'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arrays']],
+ 'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arrays', 'match', 'parameters']],
'no_blank_lines_after_phpdoc' => true,
'object_operator_without_whitespace' => true,
'binary_operator_spaces' => true,
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
deleted file mode 100644
index 4b9271e..0000000
--- a/.scrutinizer.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-filter:
- excluded_paths:
- - 'tests/'
- - 'vendor/'
- - 'tools/'
-
-# see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/
-build:
- dependencies:
- override:
- - composer update --no-interaction --no-dev
- nodes:
- php:
- tests:
- override:
- - php-scrutinizer-run --enable-security-analysis
-
-tools:
- external_code_coverage: true
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 416cfcc..56238dd 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -86,7 +86,7 @@ Lee y configura tu proyecto de acuerdo a la guía de configuración del [entorno
Una vez correctamente configurado, ejecuta las pruebas de integración:
```shell
-vendor/bin/phpunit tests/Integration --testdox --verbose
+vendor/bin/phpunit tests/Integration --testdox
```
## Ejecutar GitHub Actions localmente
@@ -97,7 +97,6 @@ puedes ejecutar el siguiente comando:
```shell
act -P ubuntu-latest=shivammathur/node:latest -W .github/workflows/build.yml
-act -P ubuntu-latest=shivammathur/node:latest -W .github/workflows/functional-tests.yml -s ENV_GPG_SECRET=**********
```
diff --git a/LICENSE b/LICENSE
index 79ffed7..5b8acbe 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2019 - 2024 PhpCfdi https://www.phpcfdi.com/
+Copyright (c) 2019 - 2025 PhpCfdi https://www.phpcfdi.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 91dfc13..1ce58df 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,20 @@
# phpcfdi/finkok
[![Source Code][badge-source]][source]
+[![Packagist PHP Version Support][badge-php-version]][php-version]
+[![Discord][badge-discord]][discord]
[![Latest Version][badge-release]][release]
[![Software License][badge-license]][license]
[![Build Status][badge-build]][build]
-[![Scrutinizer][badge-quality]][quality]
-[![Coverage Status][badge-coverage]][coverage]
+[![Reliability][badge-reliability]][reliability]
+[![Maintainability][badge-maintainability]][maintainability]
+[![Code Coverage][badge-coverage]][coverage]
+[![Violations][badge-violations]][violations]
[![Total Downloads][badge-downloads]][downloads]
> Librería para conectar con la API de servicios de FINKOK (México)
-:us: The documentation of this project is in spanish as this is the natural language for intented audience.
+:us: The documentation of this project is in spanish as this is the natural language for intended audience.
## Acerca de phpcfdi/finkok
@@ -295,6 +299,7 @@ sin temor a romper tu aplicación.
|------------------------|-------------------------------|----------------------|
| 0.1.0 | 7.2, 7.3 y 7.4 | 2019-03-29 |
| 0.3.0 | 7.3, 7.4, 8.0, 8.1, 8.2 y 8.3 | 2021-03-18 |
+| 0.6.0 | 8.1, 8.2, 8.3 y 8.4 | 2025-11-08 |
## Contribuciones
@@ -311,17 +316,25 @@ and licensed for use under the MIT License (MIT). Please see [LICENSE][] for mor
[todo]: https://github.com/phpcfdi/finkok/blob/main/docs/TODO.md
[source]: https://github.com/phpcfdi/finkok
+[php-version]: https://packagist.org/packages/phpcfdi/finkok
+[discord]: https://discord.gg/aFGYXvX
[release]: https://github.com/phpcfdi/finkok/releases
[license]: https://github.com/phpcfdi/finkok/blob/main/LICENSE
[build]: https://github.com/phpcfdi/finkok/actions/workflows/build.yml?query=branch:main
-[quality]: https://scrutinizer-ci.com/g/phpcfdi/finkok/
-[coverage]: https://scrutinizer-ci.com/g/phpcfdi/finkok/code-structure/main/code-coverage/src
+[reliability]:https://sonarcloud.io/component_measures?id=phpcfdi_finkok&metric=Reliability
+[maintainability]: https://sonarcloud.io/component_measures?id=phpcfdi_finkok&metric=Maintainability
+[coverage]: https://sonarcloud.io/component_measures?id=phpcfdi_finkok&metric=Coverage
+[violations]: https://sonarcloud.io/project/issues?id=phpcfdi_finkok&resolved=false
[downloads]: https://packagist.org/packages/phpcfdi/finkok
-[badge-source]: https://img.shields.io/badge/source-phpcfdi/finkok-blue?style=flat-square
-[badge-release]: https://img.shields.io/github/release/phpcfdi/finkok?style=flat-square
-[badge-license]: https://img.shields.io/github/license/phpcfdi/finkok?style=flat-square
-[badge-build]: https://img.shields.io/github/actions/workflow/status/phpcfdi/finkok/build.yml?branch=main&style=flat-square
-[badge-quality]: https://img.shields.io/scrutinizer/g/phpcfdi/finkok/main?style=flat-square
-[badge-coverage]: https://img.shields.io/scrutinizer/coverage/g/phpcfdi/finkok/main?style=flat-square
-[badge-downloads]: https://img.shields.io/packagist/dt/phpcfdi/finkok?style=flat-square
+[badge-source]: https://img.shields.io/badge/source-phpcfdi/finkok-blue?logo=github
+[badge-discord]: https://img.shields.io/discord/459860554090283019?logo=discord
+[badge-php-version]: https://img.shields.io/packagist/php-v/phpcfdi/finkok?logo=php
+[badge-release]: https://img.shields.io/github/release/phpcfdi/finkok?logo=git
+[badge-license]: https://img.shields.io/github/license/phpcfdi/finkok?logo=open-source-initiative
+[badge-build]: https://img.shields.io/github/actions/workflow/status/phpcfdi/finkok/build.yml?branch=main&logo=github-actions
+[badge-reliability]: https://sonarcloud.io/api/project_badges/measure?project=phpcfdi_finkok&metric=reliability_rating
+[badge-maintainability]: https://sonarcloud.io/api/project_badges/measure?project=phpcfdi_finkok&metric=sqale_rating
+[badge-coverage]: https://img.shields.io/sonar/coverage/phpcfdi_finkok/main?logo=sonarqubecloud&server=https%3A%2F%2Fsonarcloud.io
+[badge-violations]: https://img.shields.io/sonar/violations/phpcfdi_finkok/main?format=long&logo=sonarqubecloud&server=https%3A%2F%2Fsonarcloud.io
+[badge-downloads]: https://img.shields.io/packagist/dt/phpcfdi/finkok?logo=packagist
diff --git a/composer.json b/composer.json
index da0ee6f..d620be5 100644
--- a/composer.json
+++ b/composer.json
@@ -21,25 +21,26 @@
"source": "https://github.com/phpcfdi/finkok"
},
"require": {
- "php": ">=7.3",
+ "php": ">=8.1",
"ext-dom": "*",
"ext-json": "*",
"ext-openssl": "*",
"ext-soap": "*",
- "eclipxe/enum": "^0.2.0",
- "eclipxe/micro-catalog": "^0.1.0",
- "phpcfdi/cfdi-expresiones": "^3.2",
- "phpcfdi/credentials": "^1.0.1",
- "phpcfdi/xml-cancelacion": "^2.0.2",
- "psr/log": "^1.1 || ^2.0 || ^3.0",
- "robrichards/xmlseclibs": "^3.0.4"
+ "eclipxe/enum": "^0.2.7",
+ "eclipxe/micro-catalog": "^0.1.4",
+ "phpcfdi/cfdi-expresiones": "^3.3.0",
+ "phpcfdi/credentials": "^1.3.0",
+ "phpcfdi/xml-cancelacion": "^2.0.5",
+ "psr/log": "^3.0",
+ "robrichards/xmlseclibs": "^3.1.3"
},
"require-dev": {
"ext-fileinfo": "*",
- "eclipxe/cfdiutils": "^2.23.2",
- "phpcfdi/rfc": "^1.1",
- "phpunit/phpunit": "^9.5.10",
- "symfony/dotenv": "^5.1 || ^6.0 || ^7.0"
+ "eclipxe/cfdiutils": "^3.0.1",
+ "phpcfdi/rfc": "^1.2",
+ "phpunit/phpunit": "^10.5",
+ "rector/rector": "^2.2",
+ "symfony/dotenv": "^6.0 || ^7.0"
},
"prefer-stable": true,
"autoload": {
@@ -70,7 +71,7 @@
"@php tools/phpcs --colors -sp"
],
"dev:coverage": [
- "@php -dzend_extension=xdebug.so -dxdebug.mode=coverage vendor/bin/phpunit --verbose --coverage-html build/coverage/html/"
+ "@php -dzend_extension=xdebug.so -dxdebug.mode=coverage vendor/bin/phpunit --coverage-html build/coverage/html/"
],
"dev:fix-style": [
"@php tools/composer-normalize normalize",
@@ -78,7 +79,7 @@
"@php tools/phpcbf --colors -sp"
],
"dev:test": [
- "@php vendor/bin/phpunit --testdox --verbose --stop-on-failure tests/Unit",
+ "@php vendor/bin/phpunit --testdox --stop-on-failure tests/Unit",
"@php tools/phpstan analyse --no-progress --verbose"
]
},
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 79308de..6902433 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -6,6 +6,36 @@ Nos apegamos a [SEMVER](SEMVER.md), revisa la información para entender mejor e
Estos cambios se aplican y se publican, pero aún no son parte de una versión liberada.
+## Versión 0.6.0 2025-11-08
+
+Esta versión tiene cambios importantes dado que:
+- Elimina la compatibilidad con PHP 7.3, PHP 7.4 y PHP 8.0.
+- Agrega la compatibilidad con PHP 8.4.
+
+Al realizar esta actualización, también cambiaron algunos nombres de parámetros, específicamente:
+
+- `PhpCfdi\Finkok\Finkok#__construct` parámetro `factory` a `settings`.
+- `PhpCfdi\Finkok\QuickFinkok#__construct()` parámetro `factory` a `settings`.
+- `PhpCfdi\Finkok\Services\Registration\Customer#__construct()` parámetro `raw` a `data`.
+- `PhpCfdi\Finkok\Services\Stamping\StampingAlert#__construct()` parámetro `raw` a `data`.
+- `PhpCfdi\Finkok\Services\Cancel\CancelledDocument#__construct()` parámetro `raw` a `data`.
+
+Se hacen varios cambios menores:
+
+- Se actualiza el año de licencia a 2025.
+- Se actualizan las insignias a las comúnmente usadas en PhpCfdi.
+
+Se hacen varios cambios al entorno de desarrollo:
+
+- Se corrige la documentación de pruebas de integración contínua y pruebas funcionales.
+- Se elimina la integración con Scrutinizer CI. Gracias por todo.
+- Se agrega la integración con SonarQube Cloud.
+- Se actualizan los estándares de código a los comúnmente usados en PhpCfdi.
+- Se ejecutan los flujos de trabajo en PHP 8.4.
+- Se agrega PHP 8.4 a la matriz de pruebas.
+- Se elimina PHP 7.3, 7.4 y 8.0 de la matriz de pruebas.
+- Se actualizan las herramientas de desarrollo.
+
## Versión 0.5.5 2024-05-24
Se mueve `PhpCfdi\Finkok\Tests\LoggerPrinter` a `PhpCfdi\Finkok\Helpers\FileLogger` para permitir la distribución
@@ -16,7 +46,7 @@ generado por la función `print_r`. Se puede configurar para enviar también el
Se normaliza el formato de los mensajes JSON para usar `JSON_PRETTY_PRINT` y `JSON_UNESCAPED_SLASHES`.
-Se actualiza la documentación en el `README`.
+Se actualiza la documentación en el archivo `README`.
## Versión 0.5.4 2024-04-12
diff --git a/docs/PruebasDeIntegracion.md b/docs/PruebasDeIntegracion.md
index 034896d..d1c29ef 100644
--- a/docs/PruebasDeIntegracion.md
+++ b/docs/PruebasDeIntegracion.md
@@ -14,7 +14,7 @@ Los datos se encuentran en `tests/_files/certs/`:
- `EKU9003173C9.key` Archivo de llave privada (formato DER)
- `EKU9003173C9.password.bin` Archivo con el password del certificado
-Esta información es pública, por lo tanto no hay problema en publicarla aquí.
+Esta información es pública, por lo tanto, no hay problema en publicarla aquí.
Recuerda registrar este RFC en tu panel de
Si no lo haces verás errores como estos:
@@ -30,19 +30,18 @@ entornos de ejecución. Puedes usar el archivo `test/.env-example` como base.
Una vez que lo configures te recomiendo ejecutar el test inocuo de `datetime`.
```text
-php vendor/bin/phpunit --verbose --testdox tests/Integration/Services/Utilities/DatetimeServiceTest.php
-Services/Utilities/DatetimeServiceTest.php
-PHPUnit 9.5.3 by Sebastian Bergmann and contributors.
+php vendor/bin/phpunit --testdox tests/Integration/Services/Utilities/DatetimeServiceTest.php
+PHPUnit 10.5.58 by Sebastian Bergmann and contributors.
-Runtime: PHP 8.0.3
+Runtime: PHP 8.4.14
Configuration: /home/eclipxe/work/PhpCfdi/finkok/phpunit.xml.dist
Datetime Service (PhpCfdi\Finkok\Tests\Integration\Services\Utilities\DatetimeService)
- ✔ Two well known different postal codes 1173 ms
- ✔ Consume date time service 355 ms
- ✔ Consume date time service using invalid username password 314 ms
+ ✔ Two well known different postal codes
+ ✔ Consume date time service
+ ✔ Consume date time service using invalid username password
-Time: 00:01.843, Memory: 6.00 MB
+OK (3 tests, 8 assertions)
```
## Ejecución de pruebas
@@ -50,7 +49,7 @@ Time: 00:01.843, Memory: 6.00 MB
Las pruebas de integración no están incluidas en el comando `composer dev:test`. Hay que correrlas a mano ejecutando:
```shell
-vendor/bin/phpunit tests/Integration --testdox --verbose
+vendor/bin/phpunit tests/Integration --testdox
```
Lee la [guía de contribuciones](../CONTRIBUTING.md) para más información.
diff --git a/docs/PruebasDeIntegracionContinua.md b/docs/PruebasDeIntegracionContinua.md
index 8f255a7..9440557 100644
--- a/docs/PruebasDeIntegracionContinua.md
+++ b/docs/PruebasDeIntegracionContinua.md
@@ -3,18 +3,19 @@
Se ha configurado este proyecto para correr las pruebas de integración contínua utilizando la plataforma
de GitHub Actions.
-Hay dos trabajos de ejecución que ejecutan al hacer un push o un pull request sobre la rama principal:
+El flujo de trabajo `build.yml` se ejecuta en cada ocasión que se hace *push* o *pull request* sobre la rama principal
+y solo realiza las pruebas generales.
-- Prueba general de contrucción `build.yml`.
-- Pruebas funcionales `functional-test.yml`.
+El flujo de trabajo `sonarqube-cloud.yml` se ejecuta en cada ocasión que se hace *push* sobre la rama principal
+y realiza pruebas extendidas que usan credenciales encriptadas de Finkok.
## Pruebas generales
Las pruebas generales que se ejecutan tienen que ver con el estilo de código, pruebas unitarias (no funcionales),
-y anásis estático de código. Estas pruebas son las que están vinculadas con el estado de la contrucción
-en el *badge* *build*.
+y análisis estático de código. Estas pruebas son las que están vinculadas con el estado de la construcción
+en la insignia *build*.
-Adicionalmente, se ejecutan estas pruebas todos los domingos a las 16:00 horas.
+Adicionalmente, se ejecutan estas pruebas todos los domingos a las 16:00 horas (GMT-0).
## Pruebas funcionales
@@ -23,7 +24,6 @@ marcadas con la etiqueta `@group large`.
Este tipo de pruebas hace contacto con la plataforma de pruebas de Finkok, por lo que es necesario contar
con una cuenta y configurar correctamente el archivo de configuración de entorno `.env`.
-Lee el archivo de [Pruebas de Integracion](PruebasDeIntegracion.md) para más información.
### Protección de los datos de configuración de entorno
@@ -42,13 +42,17 @@ gpg --no-symkey-cache --symmetric --cipher-algo AES256 --output tests/.env-testi
```
Para desencriptar el archivo de configuración `tests/.env-testing.enc -> tests/.env` se puede usar el siguiente
-comando. Esta operación es la que se ejecuta en `functional-test.yml` usando el secreto `secrets.ENV_GPG_SECRET`.
+comando. Esta operación es la que se ejecuta en `sonarqube-cloud.yml` usando el secreto `secrets.ENV_GPG_SECRET`.
```shell
gpg --quiet --batch --yes --decrypt --output - tests/.env-testing.enc
```
-### Cobertura de código
+## Cobertura de código reportada
+
+Se está utilizando la plataforma SonarQube Cloud para análisis de código y para mostrar la cobertura de código.
+Para su ejecución es necesario que el repositorio esté configurado junto con el secreto `secrets.SONAR_TOKEN`.
+
+Se ejecutan las pruebas funcionales tal como fueron descritas anteriormente,
+pero no se excluyen las pruebas marcadas con la etiqueta `@group large`
-Las pruebas de funcionales son las que establecen la mayor cobertura de código, entonces, en su ejecución
-se genera el archivo de cobertura y se publica en Scrutinizer.
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 299f73e..3a5a85a 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -18,7 +18,6 @@
-
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 7429818..dacbb1d 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,24 +1,22 @@
+ displayDetailsOnAllIssues="true"
+ colors="true"
+ >
- ./tests/
+ tests
-
+
- ./src/
+ src
-
+
diff --git a/sonar-project.properties b/sonar-project.properties
new file mode 100644
index 0000000..d60f74e
--- /dev/null
+++ b/sonar-project.properties
@@ -0,0 +1,10 @@
+sonar.organization=phpcfdi
+sonar.projectKey=phpcfdi_finkok
+sonar.sourceEncoding=UTF-8
+sonar.language=php
+sonar.sources=src
+sonar.tests=tests
+sonar.test.exclusions=tests/_files/**/*
+sonar.working.directory=build/.scannerwork
+sonar.php.tests.reportPath=build/sonar-junit.xml
+sonar.php.coverage.reportPaths=build/sonar-coverage.xml
\ No newline at end of file
diff --git a/src/Finkok.php b/src/Finkok.php
index fd04ae2..991a723 100644
--- a/src/Finkok.php
+++ b/src/Finkok.php
@@ -42,6 +42,7 @@
*/
class Finkok
{
+ /** @var array */
protected const SERVICES_MAP = [
'stamp' => [Stamping\StampService::class, Stamping\StampingCommand::class],
'quickstamp' => [Stamping\QuickStampService::class, Stamping\StampingCommand::class],
@@ -90,12 +91,8 @@ class Finkok
],
];
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $factory)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $factory;
}
public function settings(): FinkokSettings
@@ -123,17 +120,21 @@ public function __call(string $name, array $arguments)
* @param mixed $command
* @return object|null
*/
- protected function checkCommand(string $method, $command): ?object
+ protected function checkCommand(string $method, mixed $command): ?object
{
$expected = static::SERVICES_MAP[$method][1];
if ('' === $expected) {
return null;
}
if (! is_object($command) || ! is_a($command, $expected)) {
- $type = (is_object($command)) ? get_class($command) : gettype($command);
- throw new InvalidArgumentException(
- sprintf('Call %s::%s expect %s but received %s', static::class, $method, $expected, $type)
+ $message = sprintf(
+ 'Call %s::%s expect %s but received %s',
+ static::class,
+ $method,
+ $expected,
+ get_debug_type($command),
);
+ throw new InvalidArgumentException($message);
}
return $command;
}
@@ -154,12 +155,12 @@ protected function createService(string $method): object
* @param object|null $command
* @return mixed
*/
- protected function executeService(string $method, object $service, ?object $command)
+ protected function executeService(string $method, object $service, ?object $command): mixed
{
$method = static::SERVICES_MAP[$method][2] ?? $method;
if (! is_callable([$service, $method])) {
throw new BadMethodCallException(
- sprintf('The service %s does not have a method %s', get_class($service), $method)
+ sprintf('The service %s does not have a method %s', $service::class, $method)
);
}
return $service->{$method}($command);
diff --git a/src/FinkokEnvironment.php b/src/FinkokEnvironment.php
index 4f4d5d3..c1abfb4 100644
--- a/src/FinkokEnvironment.php
+++ b/src/FinkokEnvironment.php
@@ -6,12 +6,8 @@
class FinkokEnvironment
{
- /** @var Definitions\Environment */
- private $environment;
-
- private function __construct(Definitions\Environment $environment)
+ private function __construct(private Definitions\Environment $environment)
{
- $this->environment = $environment;
}
public static function makeDevelopment(): self
diff --git a/src/FinkokSettings.php b/src/FinkokSettings.php
index 04be1ec..b736ac6 100644
--- a/src/FinkokSettings.php
+++ b/src/FinkokSettings.php
@@ -12,19 +12,15 @@
*/
class FinkokSettings
{
- /** @var string */
- private $username;
+ private string $username;
- /** @var string */
- private $password;
+ private string $password;
- /** @var FinkokEnvironment */
- private $environment;
+ private FinkokEnvironment $environment;
- /** @var SoapFactory */
- private $soapFactory;
+ private SoapFactory $soapFactory;
- public function __construct(string $username, string $password, FinkokEnvironment $environment = null)
+ public function __construct(string $username, string $password, ?FinkokEnvironment $environment = null)
{
if ('' === $username) {
throw new InvalidArgumentException('Invalid username');
@@ -67,14 +63,14 @@ public function soapFactory(): SoapFactory
* This method created a configured SoapCaller with wsdlLocation and default options
*
* @param Services $service
- * @param string $usernameKey defaults to username, if empty then it will be ommited
- * @param string $passwordKey defaults to password, if empty then it will be ommited
+ * @param string $usernameKey defaults to username, if empty then it will be omitted
+ * @param string $passwordKey defaults to password, if empty then it will be omitted
* @return SoapCaller
*/
public function createCallerForService(
Services $service,
string $usernameKey = 'username',
- string $passwordKey = 'password'
+ string $passwordKey = 'password',
): SoapCaller {
$wsdlLocation = $this->environment()->endpoint($service);
$credentials = array_merge(
diff --git a/src/Helpers/AcceptRejectSigner.php b/src/Helpers/AcceptRejectSigner.php
index ca04427..6096a15 100644
--- a/src/Helpers/AcceptRejectSigner.php
+++ b/src/Helpers/AcceptRejectSigner.php
@@ -12,36 +12,27 @@
class AcceptRejectSigner
{
- public const DEFAULT_PACRFC = 'CVD110412TF6';
-
/** @var string */
- private $uuid;
-
- /** @var CancelAnswer */
- private $answer;
+ public const DEFAULT_PACRFC = 'CVD110412TF6';
- /** @var string */
- private $pacRfc;
+ private string $pacRfc;
- /** @var DateTimeImmutable */
- private $dateTime;
+ private DateTimeImmutable $dateTime;
/**
* GetRelatedSigner constructor.
*
* @param string $uuid
* @param CancelAnswer $answer
- * @param DateTimeImmutable|null $dateTime If null or ommited then use current time and time zone
- * @param string $pacRfc If empty or ommited then uses DEFAULT_PACRFC
+ * @param DateTimeImmutable|null $dateTime If null or omitted then use current time and time zone
+ * @param string $pacRfc If empty or omitted then uses DEFAULT_PACRFC
*/
public function __construct(
- string $uuid,
- CancelAnswer $answer,
+ private string $uuid,
+ private CancelAnswer $answer,
?DateTimeImmutable $dateTime = null,
- string $pacRfc = self::DEFAULT_PACRFC
+ string $pacRfc = self::DEFAULT_PACRFC,
) {
- $this->uuid = $uuid;
- $this->answer = $answer;
$this->dateTime = $dateTime ?? new DateTimeImmutable();
$this->pacRfc = $pacRfc ?: static::DEFAULT_PACRFC;
}
diff --git a/src/Helpers/CancelSigner.php b/src/Helpers/CancelSigner.php
index 4e5590f..9f2595b 100644
--- a/src/Helpers/CancelSigner.php
+++ b/src/Helpers/CancelSigner.php
@@ -12,21 +12,16 @@
class CancelSigner
{
- /** @var CancelDocuments*/
- private $documents;
-
- /** @var DateTimeImmutable */
- private $dateTime;
+ private DateTimeImmutable $dateTime;
/**
* CancelSigner constructor
*
* @param CancelDocuments $documents
- * @param DateTimeImmutable|null $dateTime If null or ommited then use current time and time zone
+ * @param DateTimeImmutable|null $dateTime If null or omitted then use current time and time zone
*/
- public function __construct(CancelDocuments $documents, ?DateTimeImmutable $dateTime = null)
+ public function __construct(private CancelDocuments $documents, ?DateTimeImmutable $dateTime = null)
{
- $this->documents = $documents;
$this->dateTime = $dateTime ?? new DateTimeImmutable();
}
diff --git a/src/Helpers/DocumentSigner.php b/src/Helpers/DocumentSigner.php
index 81d31fe..dc5ab1f 100644
--- a/src/Helpers/DocumentSigner.php
+++ b/src/Helpers/DocumentSigner.php
@@ -13,20 +13,8 @@
class DocumentSigner
{
- /** @var string */
- private $rfc;
-
- /** @var DateTimeImmutable */
- private $date;
-
- /** @var string */
- private $content;
-
- public function __construct(string $rfc, DateTimeImmutable $date, string $content)
+ public function __construct(private string $rfc, private DateTimeImmutable $date, private string $content)
{
- $this->rfc = $rfc;
- $this->date = $date;
- $this->content = $content;
}
public function rfc(): string
diff --git a/src/Helpers/FileLogger.php b/src/Helpers/FileLogger.php
index 5fb623d..026c6b4 100644
--- a/src/Helpers/FileLogger.php
+++ b/src/Helpers/FileLogger.php
@@ -6,23 +6,19 @@
use Psr\Log\AbstractLogger;
use Psr\Log\LoggerInterface;
+use Stringable;
final class FileLogger extends AbstractLogger implements LoggerInterface
{
- /** @var string */
- public $outputFile;
-
- public function __construct(string $outputFile = 'php://stdout')
+ public function __construct(public string $outputFile = 'php://stdout')
{
- $this->outputFile = $outputFile;
}
/**
* @inheritDoc
- * @param string|\Stringable $message
* @param mixed[] $context
*/
- public function log($level, $message, array $context = []): void
+ public function log($level, string|Stringable $message, array $context = []): void
{
file_put_contents($this->outputFile, $message . PHP_EOL, FILE_APPEND);
}
diff --git a/src/Helpers/GetRelatedSigner.php b/src/Helpers/GetRelatedSigner.php
index d708341..670542f 100644
--- a/src/Helpers/GetRelatedSigner.php
+++ b/src/Helpers/GetRelatedSigner.php
@@ -11,27 +11,22 @@
class GetRelatedSigner
{
- public const DEFAULT_PACRFC = 'CVD110412TF6';
-
/** @var string */
- private $uuid;
+ public const DEFAULT_PACRFC = 'CVD110412TF6';
- /** @var RfcRole */
- private $role;
+ private RfcRole $role;
- /** @var string */
- private $pacRfc;
+ private string $pacRfc;
/**
* GetRelatedSigner constructor.
*
* @param string $uuid
- * @param RfcRole|null $role If null or ommited then uses issuer role
- * @param string $pacRfc If empty or ommited then uses DEFAULT_PACRFC
+ * @param RfcRole|null $role If null or omitted then uses issuer role
+ * @param string $pacRfc If empty or omitted then uses DEFAULT_PACRFC
*/
- public function __construct(string $uuid, RfcRole $role = null, string $pacRfc = self::DEFAULT_PACRFC)
+ public function __construct(private string $uuid, ?RfcRole $role = null, string $pacRfc = self::DEFAULT_PACRFC)
{
- $this->uuid = $uuid;
$this->role = $role ?? RfcRole::issuer();
$this->pacRfc = $pacRfc ?: static::DEFAULT_PACRFC;
}
diff --git a/src/Helpers/GetSatStatusExtractor.php b/src/Helpers/GetSatStatusExtractor.php
index 6996113..091ce52 100644
--- a/src/Helpers/GetSatStatusExtractor.php
+++ b/src/Helpers/GetSatStatusExtractor.php
@@ -14,13 +14,13 @@
use RuntimeException;
/**
- * Based on a XML string or a XML Document it can extract the appropiate values to build a GetSatStatusCommand object
+ * Based on an XML string or an XML Document it can extract the appropriate values to build a GetSatStatusCommand object
* It is using the CFDI QR expressions
*/
class GetSatStatusExtractor
{
/** @var string[] */
- private $expressionData;
+ private array $expressionData;
/**
* GetSatStatusExtractor constructor.
diff --git a/src/Helpers/JsonDecoderLogger.php b/src/Helpers/JsonDecoderLogger.php
index 94995ce..929aba2 100644
--- a/src/Helpers/JsonDecoderLogger.php
+++ b/src/Helpers/JsonDecoderLogger.php
@@ -6,6 +6,7 @@
use Psr\Log\AbstractLogger;
use Psr\Log\LoggerInterface;
+use Stringable;
/**
* Esta clase es un adaptador para convertir un mensaje de registro (log) que está
@@ -20,30 +21,23 @@
*/
final class JsonDecoderLogger extends AbstractLogger implements LoggerInterface
{
- /** @var LoggerInterface */
- private $logger;
+ private bool $useJsonValidateIfAvailable = true;
- /** @var bool */
- private $useJsonValidateIfAvailable = true;
+ private bool $alsoLogJsonMessage = false;
- /** @var bool */
- private $alsoLogJsonMessage = false;
+ private bool $lastMessageWasJsonValid = false;
- /** @var bool */
- private $lastMessageWasJsonValid = false;
-
- public function __construct(LoggerInterface $logger)
+ public function __construct(private LoggerInterface $logger)
{
- $this->logger = $logger;
}
/**
* Define si se utilizará la función \json_validate en caso de estar disponible.
*
- * @param bool|null $value El nuevo estado, si se establece NULL entonces solo devuelve el espado previo.
+ * @param bool|null $value El nuevo estado, si se establece NULL entonces solo devuelve el estado previo.
* @return bool El estado previo
*/
- public function setUseJsonValidateIfAvailable(bool $value = null): bool
+ public function setUseJsonValidateIfAvailable(?bool $value = null): bool
{
$previous = $this->useJsonValidateIfAvailable;
if (null !== $value) {
@@ -55,10 +49,10 @@ public function setUseJsonValidateIfAvailable(bool $value = null): bool
/**
* Define si también se mandará el mensaje JSON al Logger.
*
- * @param bool|null $value El nuevo estado, si se establece NULL entonces solo devuelve el espado previo.
+ * @param bool|null $value El nuevo estado, si se establece NULL entonces solo devuelve el estado previo.
* @return bool El estado previo
*/
- public function setAlsoLogJsonMessage(bool $value = null): bool
+ public function setAlsoLogJsonMessage(?bool $value = null): bool
{
$previous = $this->alsoLogJsonMessage;
if (null !== $value) {
@@ -74,10 +68,9 @@ public function lastMessageWasJsonValid(): bool
/**
* @inheritDoc
- * @param string|\Stringable $message
* @param mixed[] $context
*/
- public function log($level, $message, array $context = []): void
+ public function log($level, string|Stringable $message, array $context = []): void
{
$this->logger->log($level, $this->jsonDecode($message), $context);
if ($this->lastMessageWasJsonValid && $this->alsoLogJsonMessage) {
@@ -85,8 +78,7 @@ public function log($level, $message, array $context = []): void
}
}
- /** @param string|\Stringable $string */
- private function jsonDecode($string): string
+ private function jsonDecode(string|Stringable $string): string
{
$this->lastMessageWasJsonValid = false;
$string = strval($string);
@@ -111,8 +103,7 @@ private function jsonDecode($string): string
return $string;
}
- /** @param mixed $var */
- private function varDump($var): string
+ private function varDump(mixed $var): string
{
return print_r($var, true);
}
diff --git a/src/Internal/MethodsFilterVariablesTrait.php b/src/Internal/MethodsFilterVariablesTrait.php
new file mode 100644
index 0000000..f580134
--- /dev/null
+++ b/src/Internal/MethodsFilterVariablesTrait.php
@@ -0,0 +1,50 @@
+ */
+ private function filterArrayOfStdClass(mixed $variable): array
+ {
+ if (! is_array($variable)) {
+ return [];
+ }
+ $result = [];
+ foreach ($variable as $index => $item) {
+ if (! $item instanceof stdClass) {
+ return [];
+ }
+ $result[$index] = $item;
+ }
+ return $result;
+ }
+
+ /** @return array */
+ private function filterArrayOfStrings(mixed $variable): array
+ {
+ if (! is_array($variable)) {
+ return [];
+ }
+ $result = [];
+ foreach ($variable as $index => $item) {
+ if (! is_string($item)) {
+ return [];
+ }
+ $result[$index] = $item;
+ }
+ return $result;
+ }
+
+ private function filterString(mixed $variable): string
+ {
+ if (! is_scalar($variable)) {
+ return '';
+ }
+ return strval($variable);
+ }
+}
diff --git a/src/QuickFinkok.php b/src/QuickFinkok.php
index 575b695..fc6a56b 100644
--- a/src/QuickFinkok.php
+++ b/src/QuickFinkok.php
@@ -21,12 +21,8 @@
class QuickFinkok
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $factory)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $factory;
}
/**
@@ -118,7 +114,7 @@ public function stampQueryPending(string $uuid): Stamping\QueryPendingResult
}
/**
- * Este método es el encargado de cancelar uno o varios CFDI emitidos por medio de los web services de Finkok
+ * Este método es el encargado de cancelar uno o varios CFDI emitidos por medio de los webservices de Finkok
* Durante el proceso no se envía ningún CSD a Finkok y la solicitud firmada es creada usando los datos del CSD
*
* @param Credential $credential
@@ -152,7 +148,7 @@ public function satStatus(
string $rfcIssuer,
string $rfcRecipient,
string $uuid,
- string $total
+ string $total,
): Cancel\GetSatStatusResult {
$command = new Cancel\GetSatStatusCommand($rfcIssuer, $rfcRecipient, $uuid, $total);
$service = new Cancel\GetSatStatusService($this->settings());
@@ -187,7 +183,7 @@ public function satStatusXml(string $xmlCfdi): Cancel\GetSatStatusResult
public function obtainRelated(
Credential $credential,
string $uuid,
- RfcRole $role = null
+ ?RfcRole $role = null,
): Cancel\GetRelatedSignatureResult {
$signer = new Helpers\GetRelatedSigner($uuid, $role);
$signedRequest = $signer->sign($credential);
@@ -225,7 +221,7 @@ public function obtainPendingToCancel(string $rfc): Cancel\GetPendingResult
public function answerAcceptRejectCancellation(
Credential $credential,
string $uuid,
- CancelAnswer $answer
+ CancelAnswer $answer,
): Cancel\AcceptRejectSignatureResult {
$signer = new Helpers\AcceptRejectSigner($uuid, $answer);
$signedRequest = $signer->sign($credential);
@@ -275,7 +271,7 @@ public function serversDateTime(string $postalCode = ''): Utilities\DatetimeResu
public function reportUuids(
string $rfc,
DateTimeImmutable $since,
- DateTimeImmutable $until
+ DateTimeImmutable $until,
): Utilities\ReportUuidResult {
$command = new Utilities\ReportUuidCommand($rfc, 'I', $since, $until);
$service = new Utilities\ReportUuidService($this->settings());
@@ -312,7 +308,7 @@ public function reportTotals(
int $startYear,
int $startMonth,
int $endYear = 0,
- int $endMonth = 0
+ int $endMonth = 0,
): Utilities\ReportTotalResult {
$command = new Utilities\ReportTotalCommand($rfc, 'I', $startYear, $startMonth, $endYear, $endMonth);
$service = new Utilities\ReportTotalService($this->settings());
@@ -425,7 +421,7 @@ public function customerGetContracts(
string $name,
string $address,
string $email,
- string $snid
+ string $snid,
): Manifest\GetContractsResult {
$command = new Manifest\GetContractsCommand($rfc, $name, $address, $email, $snid);
$service = new Manifest\GetContractsService($this->settings());
@@ -444,7 +440,7 @@ public function customerGetContracts(
public function customerSendContracts(
string $snid,
string $signedPrivacy,
- string $signedContract
+ string $signedContract,
): Manifest\SignContractsResult {
$command = new Manifest\SignContractsCommand($snid, $signedPrivacy, $signedContract);
$service = new Manifest\SignContractsService($this->settings());
@@ -466,11 +462,11 @@ public function customerSignAndSendContracts(
string $snid,
string $address,
string $email,
- ?DateTimeImmutable $signedOn = null
+ ?DateTimeImmutable $signedOn = null,
): Manifest\SignContractsResult {
$rfc = $fiel->rfc();
$name = $fiel->legalName();
- $signedOn = $signedOn ?? new DateTimeImmutable();
+ $signedOn ??= new DateTimeImmutable();
$documents = $this->customerGetContracts($rfc, $name, $address, $email, $snid);
if (! $documents->success()) {
return Manifest\SignContractsResult::createFromData(
@@ -494,9 +490,9 @@ public function customerSignAndSendContracts(
public function customerGetSignedContracts(
string $snid,
string $rfc,
- SignedDocumentFormat $format = null
+ ?SignedDocumentFormat $format = null,
): Manifest\GetSignedContractsResult {
- $format = $format ?? SignedDocumentFormat::xml();
+ $format ??= SignedDocumentFormat::xml();
$command = new Manifest\GetSignedContractsCommand($snid, $rfc, $format);
$service = new Manifest\GetSignedContractsService($this->settings());
return $service->getSignedContracts($command);
@@ -544,7 +540,7 @@ public function retentionStamped(string $preCfdi): Retentions\StampedResult
}
/**
- * Este método es el encargado de cancelar un CFDI de retenciones emitido por medio de los web services de Finkok
+ * Este método es el encargado de cancelar un CFDI de retenciones emitido por medio de los webservices de Finkok
* Durante el proceso no se envía ningún CSD a Finkok y la solicitud firmada es creada usando los datos del CSD
*
* @param Credential $credential
diff --git a/src/Services/AbstractCollection.php b/src/Services/AbstractCollection.php
index 6ee79bf..ec3d1f8 100644
--- a/src/Services/AbstractCollection.php
+++ b/src/Services/AbstractCollection.php
@@ -23,7 +23,7 @@ abstract class AbstractCollection implements Countable, IteratorAggregate
abstract protected function createItemFromStdClass(stdClass $content): object;
/** @var ArrayObject */
- protected $collection;
+ protected ArrayObject $collection;
/** @param array $collection */
public function __construct(array $collection)
diff --git a/src/Services/AbstractResult.php b/src/Services/AbstractResult.php
index 03dad6d..09ee981 100644
--- a/src/Services/AbstractResult.php
+++ b/src/Services/AbstractResult.php
@@ -5,20 +5,18 @@
namespace PhpCfdi\Finkok\Services;
use InvalidArgumentException;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use stdClass;
abstract class AbstractResult
{
- /** @var stdClass */
- protected $data;
+ use MethodsFilterVariablesTrait;
- /** @var stdClass */
- protected $root;
+ protected stdClass $root;
- public function __construct(stdClass $data, string ...$meanLocation)
+ public function __construct(protected stdClass $data, string ...$meanLocation)
{
- $this->data = $data;
- $root = $this->findInDescendent($data, ...$meanLocation);
+ $root = $this->findInDescendent($this->data, ...$meanLocation);
if (! $root instanceof stdClass) {
throw new InvalidArgumentException(
sprintf('Unable to find mean object at /%s', implode('/', $meanLocation))
@@ -33,13 +31,14 @@ public function rawData(): stdClass
}
/**
- * @param stdClass|array|mixed $haystack
+ * @template T
+ * @param T $haystack
* @param string ...$location
- * @return mixed
+ * @return T|null
*/
- protected function findInDescendent($haystack, string ...$location)
+ protected function findInDescendent(mixed $haystack, string ...$location): mixed
{
- if (0 === count($location)) {
+ if ([] === $location) {
return $haystack;
}
$search = array_shift($location);
@@ -54,6 +53,6 @@ protected function findInDescendent($haystack, string ...$location)
protected function get(string $keyword): string
{
- return strval($this->root->{$keyword} ?? '');
+ return $this->filterString($this->root->{$keyword} ?? '');
}
}
diff --git a/src/Services/Cancel/AcceptRejectSignatureCommand.php b/src/Services/Cancel/AcceptRejectSignatureCommand.php
index 2e3f019..74cf770 100644
--- a/src/Services/Cancel/AcceptRejectSignatureCommand.php
+++ b/src/Services/Cancel/AcceptRejectSignatureCommand.php
@@ -6,12 +6,8 @@
class AcceptRejectSignatureCommand
{
- /** @var string */
- private $xml;
-
- public function __construct(string $xml)
+ public function __construct(private string $xml)
{
- $this->xml = $xml;
}
public function xml(): string
diff --git a/src/Services/Cancel/AcceptRejectSignatureResult.php b/src/Services/Cancel/AcceptRejectSignatureResult.php
index 553f86a..541129c 100644
--- a/src/Services/Cancel/AcceptRejectSignatureResult.php
+++ b/src/Services/Cancel/AcceptRejectSignatureResult.php
@@ -4,16 +4,17 @@
namespace PhpCfdi\Finkok\Services\Cancel;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use PhpCfdi\Finkok\Services\AbstractResult;
use stdClass;
class AcceptRejectSignatureResult extends AbstractResult
{
- /** @var AcceptRejectUuidList */
- private $uuids;
+ use MethodsFilterVariablesTrait;
- /** @var string */
- private $error;
+ private AcceptRejectUuidList $uuids;
+
+ private string $error;
public function __construct(stdClass $data)
{
@@ -23,8 +24,8 @@ public function __construct(stdClass $data)
$rechazo = $this->findInDescendent($data, $container, 'rechazo');
$this->uuids = new AcceptRejectUuidList(
array_merge(
- is_array($aceptacion) ? $aceptacion : [],
- is_array($rechazo) ? $rechazo : []
+ $this->filterArrayOfStdClass($aceptacion),
+ $this->filterArrayOfStdClass($rechazo),
)
);
$this->error = $this->get('error');
diff --git a/src/Services/Cancel/AcceptRejectSignatureService.php b/src/Services/Cancel/AcceptRejectSignatureService.php
index 4f76c68..5688ade 100644
--- a/src/Services/Cancel/AcceptRejectSignatureService.php
+++ b/src/Services/Cancel/AcceptRejectSignatureService.php
@@ -9,12 +9,8 @@
class AcceptRejectSignatureService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Cancel/AcceptRejectUuidItem.php b/src/Services/Cancel/AcceptRejectUuidItem.php
index bccb4ad..b19b381 100644
--- a/src/Services/Cancel/AcceptRejectUuidItem.php
+++ b/src/Services/Cancel/AcceptRejectUuidItem.php
@@ -8,20 +8,11 @@
class AcceptRejectUuidItem
{
- /** @var string */
- private $uuid;
-
- /** @var AcceptRejectUuidStatus */
- private $status;
-
- /** @var CancelAnswer */
- private $answer;
-
- public function __construct(string $uuid, AcceptRejectUuidStatus $status, CancelAnswer $answer)
- {
- $this->uuid = $uuid;
- $this->status = $status;
- $this->answer = $answer;
+ public function __construct(
+ private string $uuid,
+ private AcceptRejectUuidStatus $status,
+ private CancelAnswer $answer,
+ ) {
}
public function uuid(): string
diff --git a/src/Services/Cancel/AcceptRejectUuidList.php b/src/Services/Cancel/AcceptRejectUuidList.php
index 2ac734f..e181fa2 100644
--- a/src/Services/Cancel/AcceptRejectUuidList.php
+++ b/src/Services/Cancel/AcceptRejectUuidList.php
@@ -4,20 +4,19 @@
namespace PhpCfdi\Finkok\Services\Cancel;
-use ArrayIterator;
use OutOfRangeException;
use PhpCfdi\Finkok\Definitions\CancelAnswer;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use PhpCfdi\Finkok\Services\AbstractCollection;
use stdClass;
/**
- * @method AcceptRejectUuidItem get(int $index)
- * @method AcceptRejectUuidItem first()
- * @method ArrayIterator|AcceptRejectUuidItem[] getIterator()
* @extends AbstractCollection
*/
class AcceptRejectUuidList extends AbstractCollection
{
+ use MethodsFilterVariablesTrait;
+
public function findByUuidOrFail(string $uuid): AcceptRejectUuidItem
{
$found = $this->findByUuid($uuid);
@@ -40,9 +39,11 @@ public function findByUuid(string $uuid): ?AcceptRejectUuidItem
protected function createItemFromStdClass(stdClass $content): object
{
if (isset($content->{'Acepta'})) {
+ /** @var stdClass $source */
$source = $content->{'Acepta'};
$answer = CancelAnswer::accept();
} elseif (isset($content->{'Rechaza'})) {
+ /** @var stdClass $source */
$source = $content->{'Rechaza'};
$answer = CancelAnswer::reject();
} else {
@@ -50,8 +51,8 @@ protected function createItemFromStdClass(stdClass $content): object
$answer = CancelAnswer::accept();
}
return new AcceptRejectUuidItem(
- strval($source->uuid ?? ''),
- new AcceptRejectUuidStatus($source->status ?? '0'),
+ $this->filterString($source->uuid ?? ''),
+ new AcceptRejectUuidStatus($this->filterString($source->status ?? '0')),
$answer
);
}
diff --git a/src/Services/Cancel/CancelSignatureCommand.php b/src/Services/Cancel/CancelSignatureCommand.php
index 1dc2943..e4b34bd 100644
--- a/src/Services/Cancel/CancelSignatureCommand.php
+++ b/src/Services/Cancel/CancelSignatureCommand.php
@@ -8,11 +8,7 @@
class CancelSignatureCommand
{
- /** @var string */
- private $xml;
-
- /** @var CancelStorePending */
- private $storePending;
+ private CancelStorePending $storePending;
/**
* CancelSignatureCommand constructor.
@@ -20,9 +16,8 @@ class CancelSignatureCommand
* @param string $xml The signed xml
* @param CancelStorePending|null $storePending Defaults to CancelStorePending::no()
*/
- public function __construct(string $xml, CancelStorePending $storePending = null)
+ public function __construct(private string $xml, ?CancelStorePending $storePending = null)
{
- $this->xml = $xml;
$this->storePending = $storePending ?? CancelStorePending::no();
}
diff --git a/src/Services/Cancel/CancelSignatureResult.php b/src/Services/Cancel/CancelSignatureResult.php
index 319c698..cdb0b06 100644
--- a/src/Services/Cancel/CancelSignatureResult.php
+++ b/src/Services/Cancel/CancelSignatureResult.php
@@ -4,19 +4,21 @@
namespace PhpCfdi\Finkok\Services\Cancel;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use PhpCfdi\Finkok\Services\AbstractResult;
use stdClass;
class CancelSignatureResult extends AbstractResult
{
- /** @var CancelledDocuments */
- private $documents;
+ use MethodsFilterVariablesTrait;
+
+ private CancelledDocuments $documents;
public function __construct(stdClass $data)
{
parent::__construct($data, 'cancel_signatureResult');
$documents = $this->findInDescendent($data, 'cancel_signatureResult', 'Folios', 'Folio');
- $this->documents = new CancelledDocuments(is_array($documents) ? $documents : []);
+ $this->documents = new CancelledDocuments($this->filterArrayOfStdClass($documents));
}
public function documents(): CancelledDocuments
diff --git a/src/Services/Cancel/CancelSignatureService.php b/src/Services/Cancel/CancelSignatureService.php
index 95c7517..e10587c 100644
--- a/src/Services/Cancel/CancelSignatureService.php
+++ b/src/Services/Cancel/CancelSignatureService.php
@@ -9,12 +9,8 @@
class CancelSignatureService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Cancel/CancelledDocument.php b/src/Services/Cancel/CancelledDocument.php
index 94c5473..503d8fe 100644
--- a/src/Services/Cancel/CancelledDocument.php
+++ b/src/Services/Cancel/CancelledDocument.php
@@ -4,21 +4,20 @@
namespace PhpCfdi\Finkok\Services\Cancel;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use stdClass;
class CancelledDocument
{
- /** @var stdClass */
- private $data;
+ use MethodsFilterVariablesTrait;
- public function __construct(stdClass $raw)
+ public function __construct(private stdClass $data)
{
- $this->data = $raw;
}
private function get(string $keyword): string
{
- return strval($this->data->{$keyword} ?? '');
+ return $this->filterString($this->data->{$keyword} ?? '');
}
public function uuid(): string
diff --git a/src/Services/Cancel/CancelledDocuments.php b/src/Services/Cancel/CancelledDocuments.php
index 07e9825..5afcf4d 100644
--- a/src/Services/Cancel/CancelledDocuments.php
+++ b/src/Services/Cancel/CancelledDocuments.php
@@ -4,14 +4,10 @@
namespace PhpCfdi\Finkok\Services\Cancel;
-use ArrayIterator;
use PhpCfdi\Finkok\Services\AbstractCollection;
use stdClass;
/**
- * @method CancelledDocument get(int $index)
- * @method CancelledDocument first()
- * @method ArrayIterator|CancelledDocument[] getIterator()
* @extends AbstractCollection
*/
class CancelledDocuments extends AbstractCollection
diff --git a/src/Services/Cancel/GetPendingCommand.php b/src/Services/Cancel/GetPendingCommand.php
index 52c0973..05ea65a 100644
--- a/src/Services/Cancel/GetPendingCommand.php
+++ b/src/Services/Cancel/GetPendingCommand.php
@@ -6,12 +6,8 @@
class GetPendingCommand
{
- /** @var string */
- private $rfc;
-
- public function __construct(string $rfc)
+ public function __construct(private string $rfc)
{
- $this->rfc = $rfc;
}
public function rfc(): string
diff --git a/src/Services/Cancel/GetPendingResult.php b/src/Services/Cancel/GetPendingResult.php
index a1ea2a4..92fb312 100644
--- a/src/Services/Cancel/GetPendingResult.php
+++ b/src/Services/Cancel/GetPendingResult.php
@@ -4,22 +4,22 @@
namespace PhpCfdi\Finkok\Services\Cancel;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use PhpCfdi\Finkok\Services\AbstractResult;
use stdClass;
class GetPendingResult extends AbstractResult
{
+ use MethodsFilterVariablesTrait;
+
/** @var string[] */
- private $uuids;
+ private array $uuids;
public function __construct(stdClass $data)
{
parent::__construct($data, 'get_pendingResult');
$items = $this->findInDescendent($data, 'get_pendingResult', 'uuids', 'string') ?? [];
- if (! is_array($items)) {
- $items = [];
- }
- $this->uuids = $items;
+ $this->uuids = $this->filterArrayOfStrings($items);
}
/** @return string[] */
diff --git a/src/Services/Cancel/GetPendingService.php b/src/Services/Cancel/GetPendingService.php
index 4cb05b7..74e8465 100644
--- a/src/Services/Cancel/GetPendingService.php
+++ b/src/Services/Cancel/GetPendingService.php
@@ -9,12 +9,8 @@
class GetPendingService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Cancel/GetReceiptCommand.php b/src/Services/Cancel/GetReceiptCommand.php
index 6d9ddf7..38084e2 100644
--- a/src/Services/Cancel/GetReceiptCommand.php
+++ b/src/Services/Cancel/GetReceiptCommand.php
@@ -8,20 +8,8 @@
class GetReceiptCommand
{
- /** @var string */
- private $rfc;
-
- /** @var string */
- private $uuid;
-
- /** @var ReceiptType */
- private $type;
-
- public function __construct(string $rfc, string $uuid, ReceiptType $type)
+ public function __construct(private string $rfc, private string $uuid, private ReceiptType $type)
{
- $this->rfc = $rfc;
- $this->uuid = $uuid;
- $this->type = $type;
}
public function uuid(): string
diff --git a/src/Services/Cancel/GetReceiptService.php b/src/Services/Cancel/GetReceiptService.php
index d0a7892..acaaada 100644
--- a/src/Services/Cancel/GetReceiptService.php
+++ b/src/Services/Cancel/GetReceiptService.php
@@ -9,12 +9,8 @@
class GetReceiptService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Cancel/GetRelatedSignatureCommand.php b/src/Services/Cancel/GetRelatedSignatureCommand.php
index c1e7cad..e55bedc 100644
--- a/src/Services/Cancel/GetRelatedSignatureCommand.php
+++ b/src/Services/Cancel/GetRelatedSignatureCommand.php
@@ -6,12 +6,8 @@
class GetRelatedSignatureCommand
{
- /** @var string */
- private $xml;
-
- public function __construct(string $xml)
+ public function __construct(private string $xml)
{
- $this->xml = $xml;
}
public function xml(): string
diff --git a/src/Services/Cancel/GetRelatedSignatureResult.php b/src/Services/Cancel/GetRelatedSignatureResult.php
index 8a3abc9..8ac9db6 100644
--- a/src/Services/Cancel/GetRelatedSignatureResult.php
+++ b/src/Services/Cancel/GetRelatedSignatureResult.php
@@ -4,28 +4,28 @@
namespace PhpCfdi\Finkok\Services\Cancel;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use PhpCfdi\Finkok\Services\AbstractResult;
use stdClass;
class GetRelatedSignatureResult extends AbstractResult
{
- /** @var RelatedItems */
- private $parents;
+ use MethodsFilterVariablesTrait;
- /** @var RelatedItems */
- private $children;
+ private RelatedItems $parents;
- /** @var string */
- private $error;
+ private RelatedItems $children;
+
+ private string $error;
public function __construct(stdClass $data)
{
$container = 'get_related_signatureResult';
parent::__construct($data, $container);
$parents = $this->findInDescendent($data, $container, 'Padres', 'Padre');
- $this->parents = new RelatedItems(is_array($parents) ? $parents : []);
+ $this->parents = new RelatedItems($this->filterArrayOfStdClass($parents));
$children = $this->findInDescendent($data, $container, 'Hijos', 'Hijo');
- $this->children = new RelatedItems(is_array($children) ? $children : []);
+ $this->children = new RelatedItems($this->filterArrayOfStdClass($children));
$this->error = $this->get('error');
}
diff --git a/src/Services/Cancel/GetRelatedSignatureService.php b/src/Services/Cancel/GetRelatedSignatureService.php
index 669a60c..6b1978a 100644
--- a/src/Services/Cancel/GetRelatedSignatureService.php
+++ b/src/Services/Cancel/GetRelatedSignatureService.php
@@ -9,12 +9,8 @@
class GetRelatedSignatureService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Cancel/GetSatStatusCommand.php b/src/Services/Cancel/GetSatStatusCommand.php
index f7a5a84..14fa989 100644
--- a/src/Services/Cancel/GetSatStatusCommand.php
+++ b/src/Services/Cancel/GetSatStatusCommand.php
@@ -6,24 +6,12 @@
class GetSatStatusCommand
{
- /** @var string */
- private $rfcIssuer;
-
- /** @var string */
- private $rfcRecipient;
-
- /** @var string */
- private $uuid;
-
- /** @var string */
- private $total;
-
- public function __construct(string $rfcIssuer, string $rfcRecipient, string $uuid, string $total)
- {
- $this->rfcIssuer = $rfcIssuer;
- $this->rfcRecipient = $rfcRecipient;
- $this->uuid = $uuid;
- $this->total = $total;
+ public function __construct(
+ private string $rfcIssuer,
+ private string $rfcRecipient,
+ private string $uuid,
+ private string $total,
+ ) {
}
public function rfcIssuer(): string
diff --git a/src/Services/Cancel/GetSatStatusService.php b/src/Services/Cancel/GetSatStatusService.php
index 7d1bea9..7acb7b7 100644
--- a/src/Services/Cancel/GetSatStatusService.php
+++ b/src/Services/Cancel/GetSatStatusService.php
@@ -9,12 +9,8 @@
class GetSatStatusService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Cancel/RelatedItem.php b/src/Services/Cancel/RelatedItem.php
index 76d5791..9304398 100644
--- a/src/Services/Cancel/RelatedItem.php
+++ b/src/Services/Cancel/RelatedItem.php
@@ -6,20 +6,8 @@
class RelatedItem
{
- /** @var string */
- private $uuid;
-
- /** @var string */
- private $rfcEmitter;
-
- /** @var string */
- private $rfcReceiver;
-
- public function __construct(string $uuid, string $rfcEmitter, string $rfcReceiver)
+ public function __construct(private string $uuid, private string $rfcEmitter, private string $rfcReceiver)
{
- $this->uuid = $uuid;
- $this->rfcEmitter = $rfcEmitter;
- $this->rfcReceiver = $rfcReceiver;
}
public function uuid(): string
diff --git a/src/Services/Cancel/RelatedItems.php b/src/Services/Cancel/RelatedItems.php
index 5f0484b..2990837 100644
--- a/src/Services/Cancel/RelatedItems.php
+++ b/src/Services/Cancel/RelatedItems.php
@@ -4,24 +4,23 @@
namespace PhpCfdi\Finkok\Services\Cancel;
-use ArrayIterator;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use PhpCfdi\Finkok\Services\AbstractCollection;
use stdClass;
/**
- * @method RelatedItem get(int $index)
- * @method RelatedItem first()
- * @method ArrayIterator|RelatedItem[] getIterator()
* @extends AbstractCollection
*/
class RelatedItems extends AbstractCollection
{
+ use MethodsFilterVariablesTrait;
+
protected function createItemFromStdClass(stdClass $content): object
{
return new RelatedItem(
- strval($content->{'uuid'} ?? ''),
- strval($content->{'emisor'} ?? ''),
- strval($content->{'receptor'} ?? '')
+ $this->filterString($content->{'uuid'} ?? ''),
+ $this->filterString($content->{'emisor'} ?? ''),
+ $this->filterString($content->{'receptor'} ?? '')
);
}
}
diff --git a/src/Services/Manifest/GetContractsCommand.php b/src/Services/Manifest/GetContractsCommand.php
index 56e378d..f360541 100644
--- a/src/Services/Manifest/GetContractsCommand.php
+++ b/src/Services/Manifest/GetContractsCommand.php
@@ -6,28 +6,13 @@
class GetContractsCommand
{
- /** @var string */
- private $rfc;
-
- /** @var string */
- private $name;
-
- /** @var string */
- private $address;
-
- /** @var string */
- private $email;
-
- /** @var string */
- private $snid;
-
- public function __construct(string $rfc, string $name, string $address, string $email, string $snid)
- {
- $this->rfc = $rfc;
- $this->name = $name;
- $this->address = $address;
- $this->email = $email;
- $this->snid = $snid;
+ public function __construct(
+ private string $rfc,
+ private string $name,
+ private string $address,
+ private string $email,
+ private string $snid,
+ ) {
}
public function rfc(): string
diff --git a/src/Services/Manifest/GetContractsResult.php b/src/Services/Manifest/GetContractsResult.php
index f910fe5..37e31b2 100644
--- a/src/Services/Manifest/GetContractsResult.php
+++ b/src/Services/Manifest/GetContractsResult.php
@@ -33,12 +33,12 @@ public function success(): bool
public function contract(): string
{
- return base64_decode($this->get('contract'), true) ?: '';
+ return (string) base64_decode($this->get('contract'), true);
}
public function privacy(): string
{
- return base64_decode($this->get('privacy'), true) ?: '';
+ return (string) base64_decode($this->get('privacy'), true);
}
public function error(): string
diff --git a/src/Services/Manifest/GetContractsService.php b/src/Services/Manifest/GetContractsService.php
index 99772ea..50d6d13 100644
--- a/src/Services/Manifest/GetContractsService.php
+++ b/src/Services/Manifest/GetContractsService.php
@@ -9,12 +9,8 @@
class GetContractsService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
@@ -24,7 +20,7 @@ public function settings(): FinkokSettings
public function obtainContracts(GetContractsCommand $command): GetContractsResult
{
- // this empty string are for ommiting sending username and password
+ // this empty string are for omitting sending username and password
$soapCaller = $this->settings()->createCallerForService(Services::manifest(), '', '');
$rawResponse = $soapCaller->call('get_contracts_snid', [
'snid' => $command->snid(),
diff --git a/src/Services/Manifest/GetSignedContractsCommand.php b/src/Services/Manifest/GetSignedContractsCommand.php
index 565277f..99edebb 100644
--- a/src/Services/Manifest/GetSignedContractsCommand.php
+++ b/src/Services/Manifest/GetSignedContractsCommand.php
@@ -8,20 +8,8 @@
class GetSignedContractsCommand
{
- /** @var string */
- private $snid;
-
- /** @var string */
- private $rfc;
-
- /** @var SignedDocumentFormat */
- private $format;
-
- public function __construct(string $snid, string $rfc, SignedDocumentFormat $format)
+ public function __construct(private string $snid, private string $rfc, private SignedDocumentFormat $format)
{
- $this->snid = $snid;
- $this->rfc = $rfc;
- $this->format = $format;
}
public function snid(): string
diff --git a/src/Services/Manifest/GetSignedContractsResult.php b/src/Services/Manifest/GetSignedContractsResult.php
index ea44f04..f34ba7f 100644
--- a/src/Services/Manifest/GetSignedContractsResult.php
+++ b/src/Services/Manifest/GetSignedContractsResult.php
@@ -9,17 +9,13 @@
class GetSignedContractsResult extends AbstractResult
{
- /** @var bool */
- private $success;
+ private bool $success;
- /** @var string */
- private $contract;
+ private string $contract;
- /** @var string */
- private $privacy;
+ private string $privacy;
- /** @var string */
- private $error;
+ private string $error;
public function __construct(stdClass $data, bool $isBase64)
{
diff --git a/src/Services/Manifest/GetSignedContractsService.php b/src/Services/Manifest/GetSignedContractsService.php
index fcb8221..d6fc413 100644
--- a/src/Services/Manifest/GetSignedContractsService.php
+++ b/src/Services/Manifest/GetSignedContractsService.php
@@ -9,12 +9,8 @@
class GetSignedContractsService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
@@ -24,7 +20,7 @@ public function settings(): FinkokSettings
public function getSignedContracts(GetSignedContractsCommand $command): GetSignedContractsResult
{
- // this empty string are for ommiting sending username and password
+ // this empty string are for omitting sending username and password
$soapCaller = $this->settings()->createCallerForService(Services::manifest(), '', '');
$rawResponse = $soapCaller->call('get_documents', [
'snid' => $command->snid(),
diff --git a/src/Services/Manifest/SignContractsCommand.php b/src/Services/Manifest/SignContractsCommand.php
index 8867cc7..8a2c559 100644
--- a/src/Services/Manifest/SignContractsCommand.php
+++ b/src/Services/Manifest/SignContractsCommand.php
@@ -6,20 +6,8 @@
class SignContractsCommand
{
- /** @var string */
- private $snid;
-
- /** @var string */
- private $privacy;
-
- /** @var string */
- private $contract;
-
- public function __construct(string $snid, string $privacy, string $contract)
+ public function __construct(private string $snid, private string $privacy, private string $contract)
{
- $this->snid = $snid;
- $this->privacy = $privacy;
- $this->contract = $contract;
}
public function snid(): string
diff --git a/src/Services/Manifest/SignContractsService.php b/src/Services/Manifest/SignContractsService.php
index d2dc8bb..dbbedcb 100644
--- a/src/Services/Manifest/SignContractsService.php
+++ b/src/Services/Manifest/SignContractsService.php
@@ -9,12 +9,8 @@
class SignContractsService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
@@ -24,7 +20,7 @@ public function settings(): FinkokSettings
public function sendSignedContracts(SignContractsCommand $command): SignContractsResult
{
- // this empty string are for ommiting sending username and password
+ // this empty string are for omitting sending username and password
$soapCaller = $this->settings()->createCallerForService(Services::manifest(), '', '');
$rawResponse = $soapCaller->call('sign_contract', [
'snid' => $command->snid(),
diff --git a/src/Services/Registration/AddCommand.php b/src/Services/Registration/AddCommand.php
index 0d451b1..45d7d04 100644
--- a/src/Services/Registration/AddCommand.php
+++ b/src/Services/Registration/AddCommand.php
@@ -6,33 +6,16 @@
class AddCommand
{
- /** @var string */
- private $rfc;
-
- /** @var CustomerType */
- private $type;
-
- /** @var string */
- private $certificate;
-
- /** @var string */
- private $privateKey;
-
- /** @var string */
- private $passPhrase;
+ private CustomerType $type;
public function __construct(
- string $rfc,
+ private string $rfc,
?CustomerType $type = null,
- string $certificate = '',
- string $privateKey = '',
- string $passPhrase = ''
+ private string $certificate = '',
+ private string $privateKey = '',
+ private string $passPhrase = '',
) {
- $this->rfc = $rfc;
$this->type = $type ?? CustomerType::ondemand();
- $this->certificate = $certificate;
- $this->privateKey = $privateKey;
- $this->passPhrase = $passPhrase;
}
public function rfc(): string
diff --git a/src/Services/Registration/AddService.php b/src/Services/Registration/AddService.php
index aefa864..3252077 100644
--- a/src/Services/Registration/AddService.php
+++ b/src/Services/Registration/AddService.php
@@ -9,12 +9,8 @@
class AddService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Registration/AssignCommand.php b/src/Services/Registration/AssignCommand.php
index c810baf..286f60d 100644
--- a/src/Services/Registration/AssignCommand.php
+++ b/src/Services/Registration/AssignCommand.php
@@ -6,16 +6,8 @@
class AssignCommand
{
- /** @var string */
- private $rfc;
-
- /** @var int */
- private $credit;
-
- public function __construct(string $rfc, int $credit)
+ public function __construct(private string $rfc, private int $credit)
{
- $this->rfc = $rfc;
- $this->credit = $credit;
}
public function rfc(): string
diff --git a/src/Services/Registration/AssignService.php b/src/Services/Registration/AssignService.php
index 8b0e6ad..6f0885a 100644
--- a/src/Services/Registration/AssignService.php
+++ b/src/Services/Registration/AssignService.php
@@ -9,12 +9,8 @@
class AssignService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Registration/Customer.php b/src/Services/Registration/Customer.php
index 68524d3..51cc473 100644
--- a/src/Services/Registration/Customer.php
+++ b/src/Services/Registration/Customer.php
@@ -4,22 +4,19 @@
namespace PhpCfdi\Finkok\Services\Registration;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use stdClass;
class Customer
{
- /** @var stdClass */
- private $data;
+ use MethodsFilterVariablesTrait;
- /** @var CustomerStatus */
- private $status;
+ private CustomerStatus $status;
- /** @var CustomerType */
- private $type;
+ private CustomerType $type;
- public function __construct(stdClass $raw)
+ public function __construct(private stdClass $data)
{
- $this->data = $raw;
$rawStatus = $this->get('status');
if (in_array($rawStatus, CustomerStatus::toArray())) {
$this->status = new CustomerStatus($rawStatus);
@@ -31,7 +28,7 @@ public function __construct(stdClass $raw)
private function get(string $keyword): string
{
- return strval($this->data->{$keyword} ?? '');
+ return $this->filterString($this->data->{$keyword} ?? '');
}
public function status(): CustomerStatus
diff --git a/src/Services/Registration/Customers.php b/src/Services/Registration/Customers.php
index 3cc041e..750862c 100644
--- a/src/Services/Registration/Customers.php
+++ b/src/Services/Registration/Customers.php
@@ -4,15 +4,11 @@
namespace PhpCfdi\Finkok\Services\Registration;
-use ArrayIterator;
use LogicException;
use PhpCfdi\Finkok\Services\AbstractCollection;
use stdClass;
/**
- * @method Customer get(int $index)
- * @method Customer first()
- * @method ArrayIterator|Customer[] getIterator()
* @extends AbstractCollection
*/
class Customers extends AbstractCollection
diff --git a/src/Services/Registration/EditCommand.php b/src/Services/Registration/EditCommand.php
index fd87317..d3344f2 100644
--- a/src/Services/Registration/EditCommand.php
+++ b/src/Services/Registration/EditCommand.php
@@ -6,33 +6,13 @@
class EditCommand
{
- /** @var string */
- private $rfc;
-
- /** @var CustomerStatus */
- private $status;
-
- /** @var string */
- private $certificate;
-
- /** @var string */
- private $privateKey;
-
- /** @var string */
- private $passPhrase;
-
public function __construct(
- string $rfc,
- CustomerStatus $status,
- string $certificate = '',
- string $privateKey = '',
- string $passPhrase = ''
+ private string $rfc,
+ private CustomerStatus $status,
+ private string $certificate = '',
+ private string $privateKey = '',
+ private string $passPhrase = '',
) {
- $this->rfc = $rfc;
- $this->status = $status;
- $this->certificate = $certificate;
- $this->privateKey = $privateKey;
- $this->passPhrase = $passPhrase;
}
public function rfc(): string
diff --git a/src/Services/Registration/EditService.php b/src/Services/Registration/EditService.php
index 1b438d0..db92193 100644
--- a/src/Services/Registration/EditService.php
+++ b/src/Services/Registration/EditService.php
@@ -9,12 +9,8 @@
class EditService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Registration/ObtainCommand.php b/src/Services/Registration/ObtainCommand.php
index c5576c3..3ae3454 100644
--- a/src/Services/Registration/ObtainCommand.php
+++ b/src/Services/Registration/ObtainCommand.php
@@ -8,8 +8,7 @@
class ObtainCommand
{
- /** @var string */
- private $rfc;
+ private string $rfc;
public function __construct(string $rfc)
{
diff --git a/src/Services/Registration/ObtainCustomersCommand.php b/src/Services/Registration/ObtainCustomersCommand.php
index 9587a7c..36442f2 100644
--- a/src/Services/Registration/ObtainCustomersCommand.php
+++ b/src/Services/Registration/ObtainCustomersCommand.php
@@ -6,12 +6,8 @@
class ObtainCustomersCommand
{
- /** @var int */
- private $page;
-
- public function __construct(int $page)
+ public function __construct(private int $page)
{
- $this->page = $page;
}
public function page(): int
diff --git a/src/Services/Registration/ObtainCustomersResult.php b/src/Services/Registration/ObtainCustomersResult.php
index c98a22d..48fe0d2 100644
--- a/src/Services/Registration/ObtainCustomersResult.php
+++ b/src/Services/Registration/ObtainCustomersResult.php
@@ -4,19 +4,21 @@
namespace PhpCfdi\Finkok\Services\Registration;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use PhpCfdi\Finkok\Services\AbstractResult;
use stdClass;
final class ObtainCustomersResult extends AbstractResult
{
- /** @var Customers */
- private $customers;
+ use MethodsFilterVariablesTrait;
+
+ private Customers $customers;
public function __construct(stdClass $data)
{
parent::__construct($data, 'customersResult');
$customers = $this->findInDescendent($data, 'customersResult', 'users', 'ResellerUser');
- $this->customers = new Customers(is_array($customers) ? $customers : []);
+ $this->customers = new Customers($this->filterArrayOfStdClass($customers));
}
public function message(): string
diff --git a/src/Services/Registration/ObtainCustomersService.php b/src/Services/Registration/ObtainCustomersService.php
index a700fd5..c0eec5c 100644
--- a/src/Services/Registration/ObtainCustomersService.php
+++ b/src/Services/Registration/ObtainCustomersService.php
@@ -9,12 +9,8 @@
class ObtainCustomersService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Registration/ObtainResult.php b/src/Services/Registration/ObtainResult.php
index 5dd5b86..b09e5a2 100644
--- a/src/Services/Registration/ObtainResult.php
+++ b/src/Services/Registration/ObtainResult.php
@@ -4,19 +4,21 @@
namespace PhpCfdi\Finkok\Services\Registration;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use PhpCfdi\Finkok\Services\AbstractResult;
use stdClass;
class ObtainResult extends AbstractResult
{
- /** @var Customers */
- private $customers;
+ use MethodsFilterVariablesTrait;
+
+ private Customers $customers;
public function __construct(stdClass $data)
{
parent::__construct($data, 'getResult');
$customers = $this->findInDescendent($data, 'getResult', 'users', 'ResellerUser');
- $this->customers = new Customers(is_array($customers) ? $customers : []);
+ $this->customers = new Customers($this->filterArrayOfStdClass($customers));
}
public function message(): string
diff --git a/src/Services/Registration/ObtainService.php b/src/Services/Registration/ObtainService.php
index c926f25..d132740 100644
--- a/src/Services/Registration/ObtainService.php
+++ b/src/Services/Registration/ObtainService.php
@@ -9,12 +9,8 @@
class ObtainService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Registration/PageInformation.php b/src/Services/Registration/PageInformation.php
index 9c4cfb1..acad73a 100644
--- a/src/Services/Registration/PageInformation.php
+++ b/src/Services/Registration/PageInformation.php
@@ -6,38 +6,14 @@
class PageInformation
{
- /** @var int */
- private $firstRecord;
-
- /** @var int */
- private $lastRecord;
-
- /** @var int */
- private $totalRecords;
-
- /** @var int */
- private $currentPage;
-
- /** @var int */
- private $totalPages;
-
- /** @var int */
- private $pageLength;
-
public function __construct(
- int $firstRecord,
- int $lastRecord,
- int $totalRecords,
- int $currentPage,
- int $totalPages,
- int $pageLength
+ private int $firstRecord,
+ private int $lastRecord,
+ private int $totalRecords,
+ private int $currentPage,
+ private int $totalPages,
+ private int $pageLength,
) {
- $this->firstRecord = $firstRecord;
- $this->lastRecord = $lastRecord;
- $this->totalRecords = $totalRecords;
- $this->currentPage = $currentPage;
- $this->totalPages = $totalPages;
- $this->pageLength = $pageLength;
}
public static function empty(): self
diff --git a/src/Services/Registration/SwitchCommand.php b/src/Services/Registration/SwitchCommand.php
index 1f3f8ce..25e99e4 100644
--- a/src/Services/Registration/SwitchCommand.php
+++ b/src/Services/Registration/SwitchCommand.php
@@ -6,16 +6,8 @@
class SwitchCommand
{
- /** @var string */
- private $rfc;
-
- /** @var CustomerType */
- private $customerType;
-
- public function __construct(string $rfc, CustomerType $customerType)
+ public function __construct(private string $rfc, private CustomerType $customerType)
{
- $this->rfc = $rfc;
- $this->customerType = $customerType;
}
public function rfc(): string
diff --git a/src/Services/Registration/SwitchService.php b/src/Services/Registration/SwitchService.php
index c5c6bff..acb46cf 100644
--- a/src/Services/Registration/SwitchService.php
+++ b/src/Services/Registration/SwitchService.php
@@ -9,12 +9,8 @@
class SwitchService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Retentions/CancelSignatureService.php b/src/Services/Retentions/CancelSignatureService.php
index 27ec339..6002cd3 100644
--- a/src/Services/Retentions/CancelSignatureService.php
+++ b/src/Services/Retentions/CancelSignatureService.php
@@ -9,12 +9,8 @@
class CancelSignatureService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Retentions/StampService.php b/src/Services/Retentions/StampService.php
index 799f58e..cd2130f 100644
--- a/src/Services/Retentions/StampService.php
+++ b/src/Services/Retentions/StampService.php
@@ -9,12 +9,8 @@
class StampService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Retentions/StampedService.php b/src/Services/Retentions/StampedService.php
index 9bb1fb7..bbc622d 100644
--- a/src/Services/Retentions/StampedService.php
+++ b/src/Services/Retentions/StampedService.php
@@ -9,12 +9,8 @@
class StampedService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Stamping/QueryPendingCommand.php b/src/Services/Stamping/QueryPendingCommand.php
index 905f183..c4d58bf 100644
--- a/src/Services/Stamping/QueryPendingCommand.php
+++ b/src/Services/Stamping/QueryPendingCommand.php
@@ -6,12 +6,8 @@
class QueryPendingCommand
{
- /** @var string */
- private $uuid;
-
- public function __construct(string $uuid)
+ public function __construct(private string $uuid)
{
- $this->uuid = $uuid;
}
public function uuid(): string
diff --git a/src/Services/Stamping/QueryPendingService.php b/src/Services/Stamping/QueryPendingService.php
index 96c2cb0..1b5e823 100644
--- a/src/Services/Stamping/QueryPendingService.php
+++ b/src/Services/Stamping/QueryPendingService.php
@@ -9,12 +9,8 @@
class QueryPendingService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Stamping/QuickStampService.php b/src/Services/Stamping/QuickStampService.php
index c685e14..dc4e598 100644
--- a/src/Services/Stamping/QuickStampService.php
+++ b/src/Services/Stamping/QuickStampService.php
@@ -9,12 +9,8 @@
class QuickStampService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Stamping/StampService.php b/src/Services/Stamping/StampService.php
index 555168a..1fd8d4d 100644
--- a/src/Services/Stamping/StampService.php
+++ b/src/Services/Stamping/StampService.php
@@ -9,12 +9,8 @@
class StampService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Stamping/StampedService.php b/src/Services/Stamping/StampedService.php
index f3746ee..75b7008 100644
--- a/src/Services/Stamping/StampedService.php
+++ b/src/Services/Stamping/StampedService.php
@@ -9,12 +9,8 @@
class StampedService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Stamping/StampingAlert.php b/src/Services/Stamping/StampingAlert.php
index 54d895d..1e897ae 100644
--- a/src/Services/Stamping/StampingAlert.php
+++ b/src/Services/Stamping/StampingAlert.php
@@ -4,21 +4,20 @@
namespace PhpCfdi\Finkok\Services\Stamping;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use stdClass;
class StampingAlert
{
- /** @var stdClass */
- private $data;
+ use MethodsFilterVariablesTrait;
- public function __construct(stdClass $raw)
+ public function __construct(private stdClass $data)
{
- $this->data = $raw;
}
private function get(string $keyword): string
{
- return strval($this->data->{$keyword} ?? '');
+ return $this->filterString($this->data->{$keyword} ?? '');
}
public function id(): string
diff --git a/src/Services/Stamping/StampingAlerts.php b/src/Services/Stamping/StampingAlerts.php
index ecc8298..38bebee 100644
--- a/src/Services/Stamping/StampingAlerts.php
+++ b/src/Services/Stamping/StampingAlerts.php
@@ -4,14 +4,10 @@
namespace PhpCfdi\Finkok\Services\Stamping;
-use ArrayIterator;
use PhpCfdi\Finkok\Services\AbstractCollection;
use stdClass;
/**
- * @method StampingAlert get(int $index)
- * @method StampingAlert first()
- * @method ArrayIterator|StampingAlert[] getIterator()
* @extends AbstractCollection
*/
class StampingAlerts extends AbstractCollection
diff --git a/src/Services/Stamping/StampingCommand.php b/src/Services/Stamping/StampingCommand.php
index bfa636c..f5e8083 100644
--- a/src/Services/Stamping/StampingCommand.php
+++ b/src/Services/Stamping/StampingCommand.php
@@ -6,12 +6,8 @@
class StampingCommand
{
- /** @var string */
- private $xml;
-
- public function __construct(string $xml)
+ public function __construct(private string $xml)
{
- $this->xml = $xml;
}
public function xml(): string
diff --git a/src/Services/Stamping/StampingResult.php b/src/Services/Stamping/StampingResult.php
index 0f2e44e..490319b 100644
--- a/src/Services/Stamping/StampingResult.php
+++ b/src/Services/Stamping/StampingResult.php
@@ -4,19 +4,21 @@
namespace PhpCfdi\Finkok\Services\Stamping;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use PhpCfdi\Finkok\Services\AbstractResult;
use stdClass;
class StampingResult extends AbstractResult
{
- /** @var StampingAlerts */
- private $alerts;
+ use MethodsFilterVariablesTrait;
+
+ private StampingAlerts $alerts;
public function __construct(string $container, stdClass $data)
{
parent::__construct($data, $container);
$alerts = $this->findInDescendent($data, $container, 'Incidencias', 'Incidencia');
- $this->alerts = new StampingAlerts(is_array($alerts) ? $alerts : []);
+ $this->alerts = new StampingAlerts($this->filterArrayOfStdClass($alerts));
}
public function xml(): string
diff --git a/src/Services/Utilities/DatetimeCommand.php b/src/Services/Utilities/DatetimeCommand.php
index 85f33ae..9a0ab27 100644
--- a/src/Services/Utilities/DatetimeCommand.php
+++ b/src/Services/Utilities/DatetimeCommand.php
@@ -6,12 +6,8 @@
class DatetimeCommand
{
- /** @var string */
- private $postalCode;
-
- public function __construct(string $postalCode)
+ public function __construct(private string $postalCode)
{
- $this->postalCode = $postalCode;
}
public function postalCode(): string
diff --git a/src/Services/Utilities/DatetimeService.php b/src/Services/Utilities/DatetimeService.php
index 3353094..4259da5 100644
--- a/src/Services/Utilities/DatetimeService.php
+++ b/src/Services/Utilities/DatetimeService.php
@@ -9,12 +9,8 @@
class DatetimeService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Utilities/DownloadXmlCommand.php b/src/Services/Utilities/DownloadXmlCommand.php
index 7177fe7..5c5e051 100644
--- a/src/Services/Utilities/DownloadXmlCommand.php
+++ b/src/Services/Utilities/DownloadXmlCommand.php
@@ -6,20 +6,8 @@
class DownloadXmlCommand
{
- /** @var string */
- private $uuid;
-
- /** @var string */
- private $rfc;
-
- /** @var string */
- private $type;
-
- public function __construct(string $uuid, string $rfc, string $type)
+ public function __construct(private string $uuid, private string $rfc, private string $type)
{
- $this->uuid = $uuid;
- $this->rfc = $rfc;
- $this->type = $type;
}
public function uuid(): string
diff --git a/src/Services/Utilities/DownloadXmlService.php b/src/Services/Utilities/DownloadXmlService.php
index 3a4196a..4a8e727 100644
--- a/src/Services/Utilities/DownloadXmlService.php
+++ b/src/Services/Utilities/DownloadXmlService.php
@@ -9,12 +9,8 @@
class DownloadXmlService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
@@ -33,7 +29,7 @@ public function downloadXml(DownloadXmlCommand $command): DownloadXmlResult
]);
$result = new DownloadXmlResult($rawResponse);
// Finkok sometimes returns the path to the file instead of content (Ticket #18950)
- if ('.xml' === substr($result->xml(), -4)) {
+ if (str_ends_with($result->xml(), '.xml')) {
usleep(200000); // 0.2 seconds
continue;
}
diff --git a/src/Services/Utilities/ReportCreditCommand.php b/src/Services/Utilities/ReportCreditCommand.php
index 2f115f8..63bb8d0 100644
--- a/src/Services/Utilities/ReportCreditCommand.php
+++ b/src/Services/Utilities/ReportCreditCommand.php
@@ -6,12 +6,8 @@
class ReportCreditCommand
{
- /** @var string */
- private $rfc;
-
- public function __construct(string $rfc)
+ public function __construct(private string $rfc)
{
- $this->rfc = $rfc;
}
public function rfc(): string
diff --git a/src/Services/Utilities/ReportCreditResult.php b/src/Services/Utilities/ReportCreditResult.php
index aca150b..f204db8 100644
--- a/src/Services/Utilities/ReportCreditResult.php
+++ b/src/Services/Utilities/ReportCreditResult.php
@@ -4,27 +4,28 @@
namespace PhpCfdi\Finkok\Services\Utilities;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use PhpCfdi\Finkok\Services\AbstractResult;
use stdClass;
class ReportCreditResult extends AbstractResult
{
+ use MethodsFilterVariablesTrait;
+
/** @var array */
- private $items;
+ private array $items = [];
public function __construct(stdClass $data)
{
parent::__construct($data, 'report_creditResult');
- $this->items = [];
- $items = $this->findInDescendent($data, 'report_creditResult', 'result', 'ReportTotalCredit');
- if (! is_array($items)) {
- $items = [];
- }
+ $items = $this->filterArrayOfStdClass(
+ $this->findInDescendent($data, 'report_creditResult', 'result', 'ReportTotalCredit')
+ );
foreach ($items as $item) {
$this->items[] = [
- 'credit' => strval($item->credit),
- 'date' => strval($item->date),
+ 'credit' => $this->filterString($item->credit),
+ 'date' => $this->filterString($item->date),
];
}
}
diff --git a/src/Services/Utilities/ReportCreditService.php b/src/Services/Utilities/ReportCreditService.php
index 1c54fdf..cd5c764 100644
--- a/src/Services/Utilities/ReportCreditService.php
+++ b/src/Services/Utilities/ReportCreditService.php
@@ -9,12 +9,8 @@
class ReportCreditService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Utilities/ReportTotalCommand.php b/src/Services/Utilities/ReportTotalCommand.php
index acb8649..ecc7471 100644
--- a/src/Services/Utilities/ReportTotalCommand.php
+++ b/src/Services/Utilities/ReportTotalCommand.php
@@ -9,46 +9,31 @@
class ReportTotalCommand
{
- /** @var string */
- private $rfc;
+ private int $startYear;
- /** @var string */
- private $type;
+ private int $startMonth;
- /** @var int */
- private $startYear;
+ private int $endYear;
- /** @var int */
- private $startMonth;
+ private int $endMonth;
- /** @var int */
- private $endYear;
+ private string $startPeriod;
- /** @var int */
- private $endMonth;
-
- /** @var string */
- private $startPeriod;
-
- /** @var string */
- private $endPeriod;
+ private string $endPeriod;
public function __construct(
- string $rfc,
- string $type,
+ private string $rfc,
+ private string $type,
int $startYear,
int $startMonth,
int $endYear = 0,
- int $endMonth = 0
+ int $endMonth = 0,
) {
$endYear = $endYear ?: $startYear;
$endMonth = $endMonth ?: $startMonth;
$today = $this->today();
$currentYear = intval($today->format('Y'));
$currentPeriod = sprintf('%04d-%02d', $currentYear, intval($today->format('m')));
-
- $this->rfc = $rfc;
- $this->type = $type;
$this->startYear = $startYear;
$this->startMonth = $startMonth;
$this->endYear = $endYear;
@@ -109,11 +94,7 @@ public function endString(): string
{
$date = new DateTimeImmutable(sprintf('%04d-%02d-01', $this->endYear, $this->endMonth));
$today = $this->today();
- if ($this->endPeriod() === $today->format('Y-m')) {
- $date = $today;
- } else {
- $date = $date->modify('+ 1 month');
- }
+ $date = $this->endPeriod() === $today->format('Y-m') ? $today : $date->modify('+ 1 month');
return sprintf('%sT00:00:00', $date->format('Y-m-d'));
}
diff --git a/src/Services/Utilities/ReportTotalResult.php b/src/Services/Utilities/ReportTotalResult.php
index 9468d05..3524dd3 100644
--- a/src/Services/Utilities/ReportTotalResult.php
+++ b/src/Services/Utilities/ReportTotalResult.php
@@ -4,19 +4,19 @@
namespace PhpCfdi\Finkok\Services\Utilities;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use PhpCfdi\Finkok\Services\AbstractResult;
use stdClass;
class ReportTotalResult extends AbstractResult
{
- /** @var string */
- private $rfc;
+ use MethodsFilterVariablesTrait;
- /** @var string */
- private $total;
+ private string $rfc;
- /** @var string */
- private $error;
+ private string $total;
+
+ private string $error;
public function __construct(stdClass $data)
{
@@ -24,8 +24,8 @@ public function __construct(stdClass $data)
/** @var array{stdClass|null} $items */
$items = $this->findInDescendent($data, 'report_totalResult', 'result', 'ReportTotal') ?? [];
$result = $items[0] ?? (object) [];
- $this->rfc = $result->taxpayer_id ?? '';
- $this->total = strval($result->total ?? '');
+ $this->rfc = $this->filterString($result->taxpayer_id ?? '');
+ $this->total = $this->filterString($result->total ?? '');
$this->error = $this->get('error');
}
diff --git a/src/Services/Utilities/ReportTotalService.php b/src/Services/Utilities/ReportTotalService.php
index d04bef4..5813411 100644
--- a/src/Services/Utilities/ReportTotalService.php
+++ b/src/Services/Utilities/ReportTotalService.php
@@ -9,12 +9,8 @@
class ReportTotalService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/Services/Utilities/ReportUuidCommand.php b/src/Services/Utilities/ReportUuidCommand.php
index 9c68be1..2b2baa1 100644
--- a/src/Services/Utilities/ReportUuidCommand.php
+++ b/src/Services/Utilities/ReportUuidCommand.php
@@ -9,27 +9,15 @@
class ReportUuidCommand
{
- /** @var string */
- private $rfc;
-
- /** @var string */
- private $type;
-
- /** @var DateTimeImmutable */
- private $since;
-
- /** @var DateTimeImmutable */
- private $until;
-
- public function __construct(string $rfc, string $type, DateTimeImmutable $since, DateTimeImmutable $until)
- {
- if ($since > $until) {
+ public function __construct(
+ private string $rfc,
+ private string $type,
+ private DateTimeImmutable $since,
+ private DateTimeImmutable $until,
+ ) {
+ if ($this->since > $this->until) {
throw new LogicException('Since date is greater than until date');
}
- $this->rfc = $rfc;
- $this->type = $type;
- $this->since = $since;
- $this->until = $until;
}
public function rfc(): string
diff --git a/src/Services/Utilities/ReportUuidResult.php b/src/Services/Utilities/ReportUuidResult.php
index 6d71ff0..b824f47 100644
--- a/src/Services/Utilities/ReportUuidResult.php
+++ b/src/Services/Utilities/ReportUuidResult.php
@@ -4,27 +4,28 @@
namespace PhpCfdi\Finkok\Services\Utilities;
+use PhpCfdi\Finkok\Internal\MethodsFilterVariablesTrait;
use PhpCfdi\Finkok\Services\AbstractResult;
use stdClass;
class ReportUuidResult extends AbstractResult
{
+ use MethodsFilterVariablesTrait;
+
/** @var array */
- private $items;
+ private array $items = [];
public function __construct(stdClass $data)
{
parent::__construct($data, 'report_uuidResult');
- $this->items = [];
- $items = $this->findInDescendent($data, 'report_uuidResult', 'invoices', 'ReportUUID');
- if (! is_array($items)) {
- $items = [];
- }
+ $items = $this->filterArrayOfStdClass(
+ $this->findInDescendent($data, 'report_uuidResult', 'invoices', 'ReportUUID')
+ );
foreach ($items as $item) {
$this->items[] = [
- 'date' => strval($item->date),
- 'uuid' => strval($item->uuid),
+ 'date' => $this->filterString($item->date),
+ 'uuid' => $this->filterString($item->uuid),
];
}
}
diff --git a/src/Services/Utilities/ReportUuidService.php b/src/Services/Utilities/ReportUuidService.php
index cc4afbb..3be5fd0 100644
--- a/src/Services/Utilities/ReportUuidService.php
+++ b/src/Services/Utilities/ReportUuidService.php
@@ -9,12 +9,8 @@
class ReportUuidService
{
- /** @var FinkokSettings */
- private $settings;
-
- public function __construct(FinkokSettings $settings)
+ public function __construct(private FinkokSettings $settings)
{
- $this->settings = $settings;
}
public function settings(): FinkokSettings
diff --git a/src/SoapCaller.php b/src/SoapCaller.php
index 4d2353d..2c88727 100644
--- a/src/SoapCaller.php
+++ b/src/SoapCaller.php
@@ -15,24 +15,17 @@
class SoapCaller implements LoggerAwareInterface
{
- /** @var SoapClient */
- private $soapClient;
-
- /** @var array */
- private $extraParameters;
-
- /** @var LoggerInterface */
- private $logger;
+ private LoggerInterface $logger;
/**
- * @param SoapClient $soapClient
* @param array $extraParameters
*/
- public function __construct(SoapClient $soapClient, array $extraParameters = [])
- {
- $this->soapClient = $soapClient;
- $this->extraParameters = $extraParameters;
- $this->logger = new NullLogger();
+ public function __construct(
+ private SoapClient $soapClient,
+ private array $extraParameters = [],
+ ?LoggerInterface $logger = null,
+ ) {
+ $this->logger = $logger ?? new NullLogger();
}
private function soapClient(): SoapClient
diff --git a/src/SoapFactory.php b/src/SoapFactory.php
index 384c1c1..92db0fe 100644
--- a/src/SoapFactory.php
+++ b/src/SoapFactory.php
@@ -11,10 +11,9 @@
class SoapFactory implements LoggerAwareInterface
{
- /** @var LoggerInterface */
- private $logger;
+ private LoggerInterface $logger;
- public function __construct(LoggerInterface $logger = null)
+ public function __construct(?LoggerInterface $logger = null)
{
$this->logger = $logger ?? new NullLogger();
}
diff --git a/tests/Factories/PreCfdiCreatorHelper.php b/tests/Factories/PreCfdiCreatorHelper.php
index 0c6158f..7e0e3d6 100644
--- a/tests/Factories/PreCfdiCreatorHelper.php
+++ b/tests/Factories/PreCfdiCreatorHelper.php
@@ -12,49 +12,31 @@
final class PreCfdiCreatorHelper
{
- /** @var DateTimeImmutable */
- private $invoiceDate;
+ private DateTimeImmutable $invoiceDate;
- /** @var string */
- private $conceptoDescription;
+ private string $conceptoDescription;
- /** @var float */
- private $conceptoAmount;
+ private float $conceptoAmount;
- /** @var string */
- private $emisorRfc;
+ private string $emisorRfc;
- /** @var string */
- private $emisorName;
+ private string $emisorName;
- /** @var string */
- private $cerFile;
-
- /** @var string */
- private $keyPemFile;
-
- /** @var string */
- private $passPhrase;
-
- /** @var string */
- private $relation = '';
+ private string $relation = '';
/** @var string[] */
- private $relatedUuids = [];
+ private array $relatedUuids = [];
public function __construct(
- string $cerFile,
- string $keyPemFile,
- string $passPhrase
+ private string $cerFile,
+ private string $keyPemFile,
+ private string $passPhrase,
) {
- $certificate = new Certificado($cerFile);
+ $certificate = new Certificado($this->cerFile);
$this->emisorRfc = $certificate->getRfc();
$this->emisorName = $certificate->getName();
- $this->cerFile = $cerFile;
- $this->keyPemFile = $keyPemFile;
- $this->passPhrase = $passPhrase;
$this->invoiceDate = new DateTimeImmutable('now -5 minutes', new DateTimeZone('America/Mexico_City'));
- $this->conceptoDescription = 'Portable tetris gamepad pro++ ⏻';
+ $this->conceptoDescription = sprintf('Portable tetris gamepad pro++ ⏻ v1.%s', random_int(10, 99));
$this->conceptoAmount = round(random_int(1000, 4000) + random_int(0, 99) / 100, 2);
}
@@ -143,7 +125,7 @@ public function create(): string
'LugarExpedicion' => '86000',
'Exportacion' => '01', // No aplica
]);
- if ('' !== $this->relation && count($this->relatedUuids) > 0) {
+ if ('' !== $this->relation && [] !== $this->relatedUuids) {
$relacionados = $comprobante->addCfdiRelacionados(['TipoRelacion' => $this->relation]);
foreach ($this->relatedUuids as $relatedUuid) {
$relacionados->addCfdiRelacionado(['UUID' => $relatedUuid]);
diff --git a/tests/Factories/PreCfdiRetentionCreatorHelper.php b/tests/Factories/PreCfdiRetentionCreatorHelper.php
index 2504c49..253b861 100644
--- a/tests/Factories/PreCfdiRetentionCreatorHelper.php
+++ b/tests/Factories/PreCfdiRetentionCreatorHelper.php
@@ -13,50 +13,23 @@
final class PreCfdiRetentionCreatorHelper
{
- /** @var Certificado */
- private $certificate;
+ private Certificado $certificate;
- /** @var DateTimeImmutable */
- private $invoiceDate;
+ private DateTimeImmutable $invoiceDate;
- /** @var string */
- private $cveReten;
-
- /** @var string */
- private $emisorRfc;
-
- /** @var string */
- private $emisorName;
-
- /** @var string */
- private $keyPemFile;
-
- /** @var string */
- private $passPhrase;
-
- /** @var string */
- private $emisorLocation;
-
- /** @var string */
- private $emisorRegimen;
+ private string $cveReten;
public function __construct(
string $cerFile,
- string $keyPemFile,
- string $passPhrase,
- string $emisorRfc,
- string $emisorName,
- string $emisorLocation,
- string $emisorRegimen
+ private string $keyPemFile,
+ private string $passPhrase,
+ private string $emisorRfc,
+ private string $emisorName,
+ private string $emisorLocation,
+ private string $emisorRegimen,
) {
$this->certificate = new Certificado($cerFile);
- $this->emisorRfc = $emisorRfc;
- $this->emisorName = $emisorName;
- $this->keyPemFile = $keyPemFile;
- $this->passPhrase = $passPhrase;
$this->invoiceDate = new DateTimeImmutable('now -5 minutes', new DateTimeZone('America/Mexico_City'));
- $this->emisorLocation = $emisorLocation;
- $this->emisorRegimen = $emisorRegimen;
}
public function getInvoiceDate(): DateTimeImmutable
diff --git a/tests/Factories/RandomPreCfdiRetention.php b/tests/Factories/RandomPreCfdiRetention.php
index c01dc35..e82cf95 100644
--- a/tests/Factories/RandomPreCfdiRetention.php
+++ b/tests/Factories/RandomPreCfdiRetention.php
@@ -68,12 +68,10 @@ public function createValid(): string
'You must fix your RET since its is not valid (%d errors):%s%s',
count($assets->errors()),
PHP_EOL,
- implode(PHP_EOL, array_map(function (Assert $assert): string {
- return rtrim(
- sprintf('%s - %s: %s', $assert->getCode(), $assert->getTitle(), $assert->getExplanation()),
- ' :'
- );
- }, $assets->errors()))
+ implode(PHP_EOL, array_map(fn (Assert $assert): string => rtrim(
+ sprintf('%s - %s: %s', $assert->getCode(), $assert->getTitle(), $assert->getExplanation()),
+ ' :'
+ ), $assets->errors()))
));
}
diff --git a/tests/Fakes/FakeSoapCaller.php b/tests/Fakes/FakeSoapCaller.php
index 538f38d..fd0c68d 100644
--- a/tests/Fakes/FakeSoapCaller.php
+++ b/tests/Fakes/FakeSoapCaller.php
@@ -9,14 +9,12 @@
final class FakeSoapCaller extends SoapCaller
{
- /** @var stdClass */
- public $preparedResult;
+ public stdClass $preparedResult;
- /** @var string */
- public $latestCallMethodName = '';
+ public string $latestCallMethodName = '';
/** @var array */
- public $latestCallParameters = [];
+ public array $latestCallParameters = [];
/** @noinspection PhpMissingParentCallCommonInspection */
public function call(string $methodName, array $parameters): stdClass
diff --git a/tests/Fakes/FakeSoapFactory.php b/tests/Fakes/FakeSoapFactory.php
index 35a79b9..ee9d3bc 100644
--- a/tests/Fakes/FakeSoapFactory.php
+++ b/tests/Fakes/FakeSoapFactory.php
@@ -6,19 +6,23 @@
use PhpCfdi\Finkok\SoapCaller;
use PhpCfdi\Finkok\SoapFactory;
+use Psr\Log\LoggerInterface;
use SoapClient;
use stdClass;
final class FakeSoapFactory extends SoapFactory
{
- /** @var FakeSoapCaller */
- public $latestSoapCaller;
+ public FakeSoapCaller $latestSoapCaller;
- /** @var string */
- public $latestWsdlLocation;
+ public string $latestWsdlLocation;
- /** @var stdClass */
- public $preparedResult;
+ public stdClass $preparedResult;
+
+ public function __construct(?LoggerInterface $logger = null)
+ {
+ parent::__construct($logger);
+ $this->preparedResult = (object) [];
+ }
/** @noinspection PhpMissingParentCallCommonInspection */
public function createSoapClient(string $wsdlLocation): SoapClient
diff --git a/tests/Integration/IntegrationTestCase.php b/tests/Integration/IntegrationTestCase.php
index f01c2d4..47d6f04 100644
--- a/tests/Integration/IntegrationTestCase.php
+++ b/tests/Integration/IntegrationTestCase.php
@@ -23,11 +23,9 @@
abstract class IntegrationTestCase extends TestCase
{
- /** @var StampingResult|null */
- protected static $staticCurrentStampingResult;
+ protected static ?StampingResult $staticCurrentStampingResult = null;
- /** @var StampingCommand|null */
- protected static $staticCurrentStampingCommand;
+ protected static ?StampingCommand $staticCurrentStampingCommand = null;
public function newStampingCommand(): StampingCommand
{
@@ -81,7 +79,7 @@ public function createGetSatStatusCommandFromCfdiContents(string $xmlContents):
protected function createCancelSignatureCommandFromDocument(
CancelDocument $document,
- ?DateTimeImmutable $dateTime = null
+ ?DateTimeImmutable $dateTime = null,
): CancelSignatureCommand {
$credential = $this->createCsdCredential();
$signer = new CancelSigner(new CancelDocuments($document), $dateTime);
@@ -91,7 +89,7 @@ protected function createCancelSignatureCommandFromDocument(
protected function checkCanGetSatStatusOrFail(
string $cfdiContents,
string $exceptionMessage = '',
- int $waitSeconds = 120
+ int $waitSeconds = 120,
): GetSatStatusResult {
$service = new GetSatStatusService($this->createSettingsFromEnvironment());
$command = $this->createGetSatStatusCommandFromCfdiContents($cfdiContents);
diff --git a/tests/Integration/Services/Cancel/AcceptRejectSignatureServiceTest.php b/tests/Integration/Services/Cancel/AcceptRejectSignatureServiceTest.php
index 8a7026c..56ffb03 100644
--- a/tests/Integration/Services/Cancel/AcceptRejectSignatureServiceTest.php
+++ b/tests/Integration/Services/Cancel/AcceptRejectSignatureServiceTest.php
@@ -20,7 +20,7 @@ protected function createService(): AcceptRejectSignatureService
protected function createAcceptRejectSignatureCommand(
string $uuid,
- CancelAnswer $answer
+ CancelAnswer $answer,
): AcceptRejectSignatureCommand {
$signer = new AcceptRejectSigner($uuid, $answer);
$xml = $signer->sign($this->createCsdCredential());
diff --git a/tests/Integration/Services/Cancel/GetPendingServiceTest.php b/tests/Integration/Services/Cancel/GetPendingServiceTest.php
index a6a52d6..0d94b4e 100644
--- a/tests/Integration/Services/Cancel/GetPendingServiceTest.php
+++ b/tests/Integration/Services/Cancel/GetPendingServiceTest.php
@@ -15,13 +15,12 @@ public function testConsumeService(): void
// Cannot check anything else than it did not return an error
// It might be possible to create a test that ask for a cancellation that require authorization
// but this is simply unpractical for *this* test suite because
- // it takes around 16 minutes to have a CFDI with status "cancelable con autorizacion"
+ // it takes around 16 minutes to have a CFDI with status "cancelable con autorización"
$settings = $this->createSettingsFromEnvironment();
$command = new GetPendingCommand('EKU9003173C9');
$service = new GetPendingService($settings);
$result = $service->obtainPending($command);
- $this->assertTrue(is_array($result->uuids()));
$this->assertSame('', $result->error());
}
}
diff --git a/tests/Integration/Services/Cancel/GetRelatedSignatureServiceTest.php b/tests/Integration/Services/Cancel/GetRelatedSignatureServiceTest.php
index 03aeda8..bf1e64d 100644
--- a/tests/Integration/Services/Cancel/GetRelatedSignatureServiceTest.php
+++ b/tests/Integration/Services/Cancel/GetRelatedSignatureServiceTest.php
@@ -74,8 +74,8 @@ public function testConsumeServiceWithRelated(): void
// Testing only: in the wild it is expected to ask for related several seconds after the CFDI were created
if (
'' !== $result->error()
- && '2001' !== substr($result->error(), 0, 4)
- && false === strpos($result->error(), '305')
+ && ! str_starts_with($result->error(), '2001')
+ && ! str_contains($result->error(), '305')
&& ! preg_match('/UUID: \S+ No Encontrado/', $result->error())
) {
break;
diff --git a/tests/Integration/Services/Manifest/GetContractsServiceTest.php b/tests/Integration/Services/Manifest/GetContractsServiceTest.php
index a2ac662..17748c0 100644
--- a/tests/Integration/Services/Manifest/GetContractsServiceTest.php
+++ b/tests/Integration/Services/Manifest/GetContractsServiceTest.php
@@ -37,8 +37,8 @@ public function testObtainContracts(): void
$privacy = $result->privacy();
$contract = $result->contract();
- $this->assertNotEmpty($privacy, 'Cannot decode privacy statement');
- $this->assertNotEmpty($contract, 'Cannot decode contract statement');
+ $this->assertNotSame('', $privacy, 'Cannot decode privacy statement');
+ $this->assertNotSame('', $contract, 'Cannot decode contract statement');
$this->assertStringContainsString($command->rfc(), $contract);
$this->assertStringContainsString($command->name(), $contract);
// on the new manifest with Quadrum it does not include email or address
diff --git a/tests/Integration/Services/Manifest/GetSignedContractsServiceTest.php b/tests/Integration/Services/Manifest/GetSignedContractsServiceTest.php
index e9d234d..f0da96d 100644
--- a/tests/Integration/Services/Manifest/GetSignedContractsServiceTest.php
+++ b/tests/Integration/Services/Manifest/GetSignedContractsServiceTest.php
@@ -17,8 +17,8 @@ private function createService(): GetSignedContractsService
return new GetSignedContractsService($settings);
}
- /** @return array */
- public function providerGetSignedContracts(): array
+ /** @return array */
+ public static function providerGetSignedContracts(): array
{
return [
'xml' => [SignedDocumentFormat::xml(), 'text/xml'],
diff --git a/tests/Integration/Services/Manifest/SignContractsServiceTest.php b/tests/Integration/Services/Manifest/SignContractsServiceTest.php
index f9a96d7..eb44a25 100644
--- a/tests/Integration/Services/Manifest/SignContractsServiceTest.php
+++ b/tests/Integration/Services/Manifest/SignContractsServiceTest.php
@@ -19,7 +19,7 @@ private function consumeSignContracts(
string $rfc,
string $certificateFile,
string $privateKeyFile,
- string $passPhrase
+ string $passPhrase,
): SignContractsResult {
$settings = $this->createSettingsFromEnvironment();
diff --git a/tests/Integration/Services/Registration/AddServiceTest.php b/tests/Integration/Services/Registration/AddServiceTest.php
index 264570e..70a093e 100644
--- a/tests/Integration/Services/Registration/AddServiceTest.php
+++ b/tests/Integration/Services/Registration/AddServiceTest.php
@@ -55,7 +55,7 @@ public function testConsumeAddServiceWithRandomRfc(): void
// This is why it takes so long to run.
// To remove any RFC email soporte@finkok.com asking for it.
- if (! $this->getenv('FINKOK_REGISTRATION_ADD_CREATE_RANDOM_RFC')) {
+ if (! $this->getenvBool('FINKOK_REGISTRATION_ADD_CREATE_RANDOM_RFC')) {
$this->markTestSkipped('This test is skipped as will create a lot of garbage customers');
}
diff --git a/tests/Integration/Services/Registration/AssignServiceTest.php b/tests/Integration/Services/Registration/AssignServiceTest.php
index 0c430a0..287223d 100644
--- a/tests/Integration/Services/Registration/AssignServiceTest.php
+++ b/tests/Integration/Services/Registration/AssignServiceTest.php
@@ -15,6 +15,7 @@ final class AssignServiceTest extends RegistrationIntegrationTestCase
{
protected function staticSettings(): FinkokSettings
{
+ /** @var FinkokSettings|null $settings */
static $settings = null;
if (null === $settings) {
$settings = $this->createSettingsFromEnvironment();
diff --git a/tests/Integration/Services/Retentions/CancelSignatureServiceTest.php b/tests/Integration/Services/Retentions/CancelSignatureServiceTest.php
index a7b1ff9..6531a6b 100644
--- a/tests/Integration/Services/Retentions/CancelSignatureServiceTest.php
+++ b/tests/Integration/Services/Retentions/CancelSignatureServiceTest.php
@@ -13,8 +13,7 @@
*/
final class CancelSignatureServiceTest extends RetentionsTestCase
{
- /** @var QuickFinkok */
- private $quickFinkok;
+ private QuickFinkok $quickFinkok;
protected function setUp(): void
{
diff --git a/tests/Integration/Services/Retentions/RetentionsUsingExistentRetentionTest.php b/tests/Integration/Services/Retentions/RetentionsUsingExistentRetentionTest.php
index bacc326..ee0c3ff 100644
--- a/tests/Integration/Services/Retentions/RetentionsUsingExistentRetentionTest.php
+++ b/tests/Integration/Services/Retentions/RetentionsUsingExistentRetentionTest.php
@@ -13,14 +13,11 @@
*/
final class RetentionsUsingExistentRetentionTest extends RetentionsTestCase
{
- /** @var QuickFinkok */
- private $quickFinkok;
+ private QuickFinkok $quickFinkok;
- /** @var string|null */
- protected static $staticCurrentStampPrecfdi;
+ protected static ?string $staticCurrentStampPrecfdi = null;
- /** @var StampResult|null */
- protected static $staticCurrentStampResult;
+ protected static ?StampResult $staticCurrentStampResult = null;
protected function currentRetentionsPreCfdi(): string
{
diff --git a/tests/TestCase.php b/tests/TestCase.php
index a1baeec..08f66e5 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -14,7 +14,7 @@
abstract class TestCase extends \PHPUnit\Framework\TestCase
{
- public function createSettingsFromEnvironment(SoapFactory $soapFactory = null): FinkokSettings
+ public function createSettingsFromEnvironment(?SoapFactory $soapFactory = null): FinkokSettings
{
$settings = new FinkokSettings(
$this->getenv('FINKOK_USERNAME') ?: 'username-non-set',
@@ -25,12 +25,12 @@ public function createSettingsFromEnvironment(SoapFactory $soapFactory = null):
$settings->changeSoapFactory($soapFactory);
}
- if ($this->getenv('FINKOK_LOG_CALLS')) {
+ if ($this->getenvBool('FINKOK_LOG_CALLS')) {
$loggerOutputFile = sprintf(
'%s/../build/tests/%s-%s-%s.txt',
__DIR__,
(new DateTimeImmutable())->format('YmdHis.u'),
- $this->getName(),
+ $this->name(),
uniqid()
);
$logger = new JsonDecoderLogger(new FileLogger($loggerOutputFile));
@@ -75,6 +75,13 @@ public static function fileContent(string $path): string
public static function getenv(string $key): string
{
- return $_ENV[$key] ?? '';
+ $value = $_ENV[$key] ?? '';
+ return (is_scalar($value)) ? strval($value) : '';
+ }
+
+ public static function getenvBool(string $key): bool
+ {
+ $value = static::getenv($key);
+ return ! in_array($value, ['', '0', 'no', 'false']);
}
}
diff --git a/tests/Unit/FinkokEnvironmentTest.php b/tests/Unit/FinkokEnvironmentTest.php
index ad77f55..41d4718 100644
--- a/tests/Unit/FinkokEnvironmentTest.php
+++ b/tests/Unit/FinkokEnvironmentTest.php
@@ -30,10 +30,12 @@ public function testEndpointOverridesWhenServiceIsManifest(): void
$environment = FinkokEnvironment::makeDevelopment();
$cancel = $environment->endpoint(Services::cancel());
+ /** @phpstan-ignore argument.type (Parameter #1 expects non-empty-string) */
$this->assertStringStartsWith($environment->server(), $cancel);
$this->assertStringNotContainsString('//', substr($cancel, 8));
$manifest = $environment->endpoint(Services::manifest());
+ /** @phpstan-ignore argument.type (Parameter #1 expects non-empty-string) */
$this->assertStringStartsWith(EnvironmentManifest::development()->value(), $manifest);
$this->assertStringNotContainsString('//', substr($manifest, 8));
}
diff --git a/tests/Unit/FinkokTest.php b/tests/Unit/FinkokTest.php
index dabe1f4..b58bb54 100644
--- a/tests/Unit/FinkokTest.php
+++ b/tests/Unit/FinkokTest.php
@@ -29,10 +29,10 @@ public function testConstructor(): void
public function testInvokingOneMappedMagicMethod(): void
{
- /** @var StampingResult $result */
+ /** @var StampingResult&MockObject $result */
$result = $this->createMock(StampingResult::class);
- /** @var StampingCommand $command */
+ /** @var StampingCommand&MockObject $command */
$command = $this->createMock(StampingCommand::class);
/** @var FinkokSettings&MockObject $settings */
@@ -60,7 +60,7 @@ public function testBadMethodCall(): void
$finkok = new Finkok($settings);
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage('Helper invalid-method is not registered');
- $finkok->{'invalid-method'}();
+ $finkok->{'invalid-method'}(); /** @phpstan-ignore-line method.notFound */
}
public function testMagicCallWithInvalidParameter(): void
@@ -74,9 +74,9 @@ public function testMagicCallWithInvalidParameter(): void
$this->expectExceptionMessage(
'Call PhpCfdi\Finkok\Finkok::getContracts'
. ' expect PhpCfdi\Finkok\Services\Manifest\GetContractsCommand'
- . ' but received ' . get_class($command)
+ . ' but received ' . $command::class
);
- $finkok->{'getContracts'}($command);
+ $finkok->{'getContracts'}($command); /** @phpstan-ignore-line argument.type */
}
public function testExecuteServiceWithCallNameDifferentFromServiceMethodName(): void
@@ -110,9 +110,9 @@ public function exposedExecuteService(string $method, object $service, ?object $
public function testInvokingOneMappedMagicMethodWithDifferentName(): void
{
- /** @var GetContractsResult $result */
+ /** @var GetContractsResult&MockObject $result */
$result = $this->createMock(GetContractsResult::class);
- /** @var GetContractsCommand $command */
+ /** @var GetContractsCommand&MockObject $command */
$command = $this->createMock(GetContractsCommand::class);
/** @var GetContractsService&MockObject $service */
$service = $this->createMock(GetContractsService::class);
diff --git a/tests/Unit/Helpers/AcceptRejectSignerTest.php b/tests/Unit/Helpers/AcceptRejectSignerTest.php
index 1103878..16efdae 100644
--- a/tests/Unit/Helpers/AcceptRejectSignerTest.php
+++ b/tests/Unit/Helpers/AcceptRejectSignerTest.php
@@ -21,7 +21,7 @@ public function testCreateAndSign(): void
$this->assertSame($uuid, $signer->uuid());
$this->assertSame($answer, $signer->answer());
$this->assertSame($date, $signer->dateTime());
- $this->assertSame($signer::DEFAULT_PACRFC, $signer->pacRfc());
+ $this->assertSame(AcceptRejectSigner::DEFAULT_PACRFC, $signer->pacRfc());
$signed = $signer->sign($this->createCsdCredential());
diff --git a/tests/Unit/Helpers/DocumentSignerTest.php b/tests/Unit/Helpers/DocumentSignerTest.php
index b8e511c..d328a11 100644
--- a/tests/Unit/Helpers/DocumentSignerTest.php
+++ b/tests/Unit/Helpers/DocumentSignerTest.php
@@ -10,6 +10,7 @@
use PhpCfdi\Credentials\Credential;
use PhpCfdi\Finkok\Helpers\DocumentSigner;
use PhpCfdi\Finkok\Tests\TestCase;
+use PHPUnit\Framework\MockObject\MockObject;
final class DocumentSignerTest extends TestCase
{
@@ -42,7 +43,7 @@ public function testSignDocumentUsingCredentialWithoutRootElement(): void
$content = 'Lorem Ipsum';
$docSigner = new DocumentSigner($rfc, $date, $content);
- /** @var Credential $credential */
+ /** @var Credential&MockObject $credential */
$credential = $this->createMock(Credential::class);
$documentWithoutRootElement = new DOMDocument();
$this->expectException(LogicException::class);
diff --git a/tests/Unit/Helpers/GetRelatedSignerTest.php b/tests/Unit/Helpers/GetRelatedSignerTest.php
index b998784..b69ae71 100644
--- a/tests/Unit/Helpers/GetRelatedSignerTest.php
+++ b/tests/Unit/Helpers/GetRelatedSignerTest.php
@@ -18,7 +18,7 @@ public function testCreateAndSign(): void
$signer = new GetRelatedSigner($uuid, $role);
$this->assertSame($uuid, $signer->uuid());
$this->assertSame($role, $signer->role());
- $this->assertSame($signer::DEFAULT_PACRFC, $signer->pacRfc());
+ $this->assertSame(GetRelatedSigner::DEFAULT_PACRFC, $signer->pacRfc());
$signed = $signer->sign($this->createCsdCredential());
diff --git a/tests/Unit/Helpers/JsonDecoderLoggerTest.php b/tests/Unit/Helpers/JsonDecoderLoggerTest.php
index 0c8f631..2bf7ba4 100644
--- a/tests/Unit/Helpers/JsonDecoderLoggerTest.php
+++ b/tests/Unit/Helpers/JsonDecoderLoggerTest.php
@@ -14,25 +14,25 @@ final class JsonDecoderLoggerTest extends TestCase
public function testSetAlsoLogJsonMessage(): void
{
$decoder = new JsonDecoderLogger(new NullLogger());
- $this->assertSame(false, $decoder->setAlsoLogJsonMessage(null));
+ $this->assertSame(false, $decoder->setAlsoLogJsonMessage());
$this->assertSame(false, $decoder->setAlsoLogJsonMessage(true));
$this->assertSame(true, $decoder->setAlsoLogJsonMessage(true));
- $this->assertSame(true, $decoder->setAlsoLogJsonMessage(null));
+ $this->assertSame(true, $decoder->setAlsoLogJsonMessage());
$this->assertSame(true, $decoder->setAlsoLogJsonMessage(false));
$this->assertSame(false, $decoder->setAlsoLogJsonMessage(false));
- $this->assertSame(false, $decoder->setAlsoLogJsonMessage(null));
+ $this->assertSame(false, $decoder->setAlsoLogJsonMessage());
}
public function testSetUseJsonValidateIfAvailable(): void
{
$decoder = new JsonDecoderLogger(new NullLogger());
- $this->assertSame(true, $decoder->setUseJsonValidateIfAvailable(null));
+ $this->assertSame(true, $decoder->setUseJsonValidateIfAvailable());
$this->assertSame(true, $decoder->setUseJsonValidateIfAvailable(false));
$this->assertSame(false, $decoder->setUseJsonValidateIfAvailable(false));
- $this->assertSame(false, $decoder->setUseJsonValidateIfAvailable(null));
+ $this->assertSame(false, $decoder->setUseJsonValidateIfAvailable());
$this->assertSame(false, $decoder->setUseJsonValidateIfAvailable(true));
$this->assertSame(true, $decoder->setUseJsonValidateIfAvailable(true));
- $this->assertSame(true, $decoder->setUseJsonValidateIfAvailable(null));
+ $this->assertSame(true, $decoder->setUseJsonValidateIfAvailable());
}
public function testLastMessageWasJsonValidReturnFalseWithoutCall(): void
@@ -42,7 +42,7 @@ public function testLastMessageWasJsonValidReturnFalseWithoutCall(): void
}
/** @return array */
- public function providerUseJsonValidateIfAvailable(): array
+ public static function providerUseJsonValidateIfAvailable(): array
{
return [
'use json_validate' => [true],
@@ -53,8 +53,7 @@ public function providerUseJsonValidateIfAvailable(): array
/** @dataProvider providerUseJsonValidateIfAvailable */
public function testLogSendValidJsonMessageToLogger(bool $useJsonValidateIfAvailable): void
{
- /** @var string $jsonMessage */
- $jsonMessage = json_encode(['foo' => 'bar']);
+ $jsonMessage = (string) json_encode(['foo' => 'bar']);
$textMessage = print_r(json_decode($jsonMessage), true);
/** @var NullLogger&MockObject $logger */
$logger = $this->createMock(NullLogger::class);
@@ -83,8 +82,7 @@ public function testLogSendInvalidJsonMessageToLogger(bool $useJsonValidateIfAva
public function testLogSendTextMessageToLoggerAndJson(): void
{
- /** @var string $jsonMessage */
- $jsonMessage = json_encode(['foo' => 'bar']);
+ $jsonMessage = (string) json_encode(['foo' => 'bar']);
$textMessage = print_r(json_decode($jsonMessage), true);
/** @var NullLogger&MockObject $logger */
$logger = $this->createMock(NullLogger::class);
@@ -96,8 +94,8 @@ public function testLogSendTextMessageToLoggerAndJson(): void
$logger->expects($matcher)->method('log')->with(
'debug',
$this->callback(
- function ($message) use ($matcher, $expectedParameters) {
- $this->assertSame($expectedParameters[$matcher->getInvocationCount() - 1], $message);
+ function ($message) use ($matcher, $expectedParameters): bool {
+ $this->assertSame($expectedParameters[$matcher->numberOfInvocations() - 1], $message);
return true;
}
),
diff --git a/tests/Unit/QuickFinkokTest.php b/tests/Unit/QuickFinkokTest.php
index 7ac25bd..61a7719 100644
--- a/tests/Unit/QuickFinkokTest.php
+++ b/tests/Unit/QuickFinkokTest.php
@@ -23,8 +23,7 @@
/** @covers \PhpCfdi\Finkok\QuickFinkok */
final class QuickFinkokTest extends TestCase
{
- /** @var FakeSoapFactory */
- private $soapFactory;
+ private FakeSoapFactory $soapFactory;
private function createdPreparedQuickFinkok(stdClass $rawData): QuickFinkok
{
diff --git a/tests/Unit/Services/AbstractResultTest.php b/tests/Unit/Services/AbstractResultTest.php
index 1a1fbc2..fae4573 100644
--- a/tests/Unit/Services/AbstractResultTest.php
+++ b/tests/Unit/Services/AbstractResultTest.php
@@ -10,11 +10,9 @@
final class AbstractResultTest extends TestCase
{
- /** @var stdClass */
- private $data;
+ private stdClass $data;
- /** @var TestingResult */
- private $result;
+ private TestingResult $result;
protected function setUp(): void
{
diff --git a/tests/Unit/Services/Cancel/AcceptRejectUuidListTest.php b/tests/Unit/Services/Cancel/AcceptRejectUuidListTest.php
index bf1bbc3..65b08f6 100644
--- a/tests/Unit/Services/Cancel/AcceptRejectUuidListTest.php
+++ b/tests/Unit/Services/Cancel/AcceptRejectUuidListTest.php
@@ -11,8 +11,7 @@
final class AcceptRejectUuidListTest extends TestCase
{
- /** @var AcceptRejectUuidList */
- private $list;
+ private AcceptRejectUuidList $list;
protected function setUp(): void
{
diff --git a/tests/Unit/Services/Registration/CustomersTest.php b/tests/Unit/Services/Registration/CustomersTest.php
index 5dd2b3d..f469e75 100644
--- a/tests/Unit/Services/Registration/CustomersTest.php
+++ b/tests/Unit/Services/Registration/CustomersTest.php
@@ -19,8 +19,8 @@ public function testCreateUsingNoItems(): void
public function testFindByRfc(): void
{
- /** @var stdClass $data */
$data = json_decode($this->fileContentPath('registration-get-response.json'));
+ /** @phpstan-ignore-next-line */
$customers = new Customers($data->getResult->users->ResellerUser);
$known = $customers->findByRfc('MAG041126GT8');
if (null === $known) {
@@ -35,6 +35,7 @@ public function testGetByRfcUsingExistentRfc(): void
$expectedRfc = 'MAG041126GT8';
/** @var stdClass $data */
$data = json_decode($this->fileContentPath('registration-get-response.json'));
+ /** @phpstan-ignore-next-line */
$customers = new Customers($data->getResult->users->ResellerUser);
$this->assertSame($expectedRfc, $customers->getByRfc($expectedRfc)->rfc());
}
@@ -43,6 +44,7 @@ public function testGetByRfcUsingNonExistentRfcThrowsException(): void
{
/** @var stdClass $data */
$data = json_decode($this->fileContentPath('registration-get-response.json'));
+ /** @phpstan-ignore-next-line */
$customers = new Customers($data->getResult->users->ResellerUser);
$this->expectException(LogicException::class);
diff --git a/tests/Unit/Services/Retentions/CancelSignatureServiceTest.php b/tests/Unit/Services/Retentions/CancelSignatureServiceTest.php
index e9963bc..7fe6c9e 100644
--- a/tests/Unit/Services/Retentions/CancelSignatureServiceTest.php
+++ b/tests/Unit/Services/Retentions/CancelSignatureServiceTest.php
@@ -35,6 +35,7 @@ public function testServiceUsingPreparedResult(): void
$this->assertSame('x-seguimiento-cancelacion', $result->tracing());
$caller = $soapFactory->latestSoapCaller;
+ /** @phpstan-ignore argument.type (Parameter #1 expects non-empty-string) */
$this->assertStringEndsWith(Services::retentions()->value(), $soapFactory->latestWsdlLocation);
$this->assertSame('cancel_signature', $caller->latestCallMethodName);
$this->assertArrayHasKey('xml', $caller->latestCallParameters);
diff --git a/tests/Unit/Services/Stamping/StampingAlertsTest.php b/tests/Unit/Services/Stamping/StampingAlertsTest.php
index 7df5fbb..6b1465e 100644
--- a/tests/Unit/Services/Stamping/StampingAlertsTest.php
+++ b/tests/Unit/Services/Stamping/StampingAlertsTest.php
@@ -6,7 +6,6 @@
use PhpCfdi\Finkok\Services\Stamping\StampingAlerts;
use PhpCfdi\Finkok\Tests\TestCase;
-use stdClass;
final class StampingAlertsTest extends TestCase
{
@@ -53,9 +52,9 @@ public function testHydrate(): void
public function testGettingAnAlertByIndex(): void
{
- /** @var stdClass $data */
$data = json_decode($this->fileContentPath('stamp-response-with-alerts.json'));
- $alerts = new StampingAlerts($data->{'stampResult'}->{'Incidencias'}->{'Incidencia'} ?? []);
+ /** @phpstan-ignore-next-line */
+ $alerts = new StampingAlerts($data->stampResult->Incidencias->Incidencia ?? []);
$this->assertSame('FAKE2', $alerts->get(1)->errorCode());
}
diff --git a/tests/Unit/Services/Utilities/ReportTotalCommandTest.php b/tests/Unit/Services/Utilities/ReportTotalCommandTest.php
index 3343f53..31f150a 100644
--- a/tests/Unit/Services/Utilities/ReportTotalCommandTest.php
+++ b/tests/Unit/Services/Utilities/ReportTotalCommandTest.php
@@ -143,19 +143,15 @@ public function testCreateWithStartPeriodInPastAndEndPeriodInFuture(): void
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Cannot combine multiple past months with current/future months');
new class ($today, 'x-rfc', 'I', 2019, 1, $year, $month) extends ReportTotalCommand {
- /** @var DateTimeImmutable */
- private $today;
-
public function __construct(
- DateTimeImmutable $today,
+ private DateTimeImmutable $today,
string $rfc,
string $type,
int $startYear,
int $startMonth,
int $endYear = 0,
- int $endMonth = 0
+ int $endMonth = 0,
) {
- $this->today = $today;
parent::__construct($rfc, $type, $startYear, $startMonth, $endYear, $endMonth);
}
diff --git a/tests/stamp-precfdi-devenv.php b/tests/stamp-precfdi-devenv.php
index 49a13f1..7ef447f 100644
--- a/tests/stamp-precfdi-devenv.php
+++ b/tests/stamp-precfdi-devenv.php
@@ -16,12 +16,8 @@
require_once __DIR__ . '/bootstrap.php';
exit(call_user_func(new class ($argv[0] ?? '') {
- /** @var string */
- private $command;
-
- public function __construct(string $command)
+ public function __construct(private string $command)
{
- $this->command = $command;
}
public function __invoke(string $preCfdiPath): int
@@ -30,7 +26,7 @@ public function __invoke(string $preCfdiPath): int
$this->showHelp();
return 0;
}
- $debug = (bool) TestCase::getenv('FINKOK_LOG_CALLS');
+ $debug = TestCase::getenvBool('FINKOK_LOG_CALLS');
try {
if (! file_exists($preCfdiPath)) {
throw new Exception("File $preCfdiPath does not exists");
@@ -64,7 +60,7 @@ public function __invoke(string $preCfdiPath): int
} catch (Throwable $exception) {
file_put_contents(
'php://stderr',
- sprintf("%s: %s\n", get_class($exception), $exception->getMessage()),
+ sprintf("%s: %s\n", $exception::class, $exception->getMessage()),
FILE_APPEND
);
return (int) $exception->getCode() ?: 1;