Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
php-version: '8.4'
coverage: none
tools: composer-normalize
env:
Expand All @@ -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:
Expand Down Expand Up @@ -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
env:
Expand All @@ -93,18 +93,18 @@ jobs:
run: phpstan analyse --no-progress --verbose

tests:
name: Tests on PHP ${{ matrix.php-versions }}
name: Tests on PHP ${{ matrix.php-version }}
runs-on: "ubuntu-latest"
strategy:
matrix:
php-versions: ['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
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: ${{ matrix.php-version }}
coverage: none
tools: composer:v2
env:
Expand All @@ -121,4 +121,4 @@ jobs:
- name: Install project dependencies
run: composer upgrade --no-interaction --no-progress --prefer-dist
- name: Tests (phpunit)
run: vendor/bin/phpunit --testdox --verbose
run: vendor/bin/phpunit --testdox
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ on:

# Actions
# shivammathur/setup-php@v2 https://github.com/marketplace/actions/setup-php-action
# sonarsource/sonarcloud-github-action@master https://github.com/marketplace/actions/sonarcloud-scan
# SonarSource/sonarqube-scan-action@v5 https://github.com/marketplace/actions/official-sonarqube-scan

jobs:

tests-coverage:
name: Tests on PHP 8.0 (code coverage)
name: Tests on PHP (code coverage)
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
php-version: '8.4'
coverage: xdebug
tools: composer:v2
env:
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Install project dependencies
run: composer upgrade --no-interaction --no-progress --prefer-dist
- name: Create code coverage
run: vendor/bin/phpunit --testdox --verbose --coverage-xml=build/coverage --coverage-clover=build/coverage/clover.xml --log-junit=build/coverage/junit.xml
run: vendor/bin/phpunit --testdox --coverage-xml=build/coverage --coverage-clover=build/coverage/clover.xml --log-junit=build/coverage/junit.xml
- name: Store code coverage
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
php-version: '8.4'
coverage: none
tools: composer:v2
- name: Get composer cache directory
Expand All @@ -103,7 +103,6 @@ jobs:
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/sonarcloud-github-action@master
uses: SonarSource/sonarqube-scan-action@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
10 changes: 5 additions & 5 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="php-cs-fixer" version="^3.58.1" installed="3.58.1" location="./tools/php-cs-fixer" copy="false"/>
<phar name="phpcs" version="^3.10.1" installed="3.10.1" location="./tools/phpcs" copy="false"/>
<phar name="phpcbf" version="^3.10.1" installed="3.10.1" location="./tools/phpcbf" copy="false"/>
<phar name="phpstan" version="^1.11.4" installed="1.11.4" location="./tools/phpstan" copy="false"/>
<phar name="composer-normalize" version="^2.42.0" installed="2.42.0" location="./tools/composer-normalize" copy="false"/>
<phar name="php-cs-fixer" version="^3.75.0" installed="3.75.0" location="./tools/php-cs-fixer" copy="false"/>
<phar name="phpcs" version="^3.12.1" installed="3.12.1" location="./tools/phpcs" copy="false"/>
<phar name="phpcbf" version="^3.12.1" installed="3.12.1" location="./tools/phpcbf" copy="false"/>
<phar name="phpstan" version="^2.1.11" installed="2.1.11" location="./tools/phpstan" copy="false"/>
<phar name="composer-normalize" version="^2.46.0" installed="2.46.0" location="./tools/composer-normalize" copy="false"/>
</phive>
4 changes: 2 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
->setRules([
'@PSR12' => true,
'@PSR12:risky' => true,
'@PHP71Migration:risky' => true,
'@PHP73Migration' => true,
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
// symfony
'class_attributes_separation' => true,
'whitespace_after_comma_in_array' => true,
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ $pfxReader = new PfxReader();
$credential = $pfxReader->createCredentialFromContents('contenido-del-archivo', 'pfx-passphrase');

// crea un objeto Credential dada la ruta local de un archivo pfx
$credential = $pfxReader->createCredentialsFromFile('pfxFilePath', 'pfx-passphrase');
$credential = $pfxReader->createCredentialFromFile('pfxFilePath', 'pfx-passphrase');
```

## Compatibilidad
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"keywords": [
"efirma",
"fiel",
"csd",
"sat",
"cfdi",
"sello",
Expand All @@ -22,14 +23,14 @@
"source": "https://github.com/phpcfdi/credentials"
},
"require": {
"php": ">=7.3",
"php": ">=8.1",
"ext-mbstring": "*",
"ext-openssl": "*",
"eclipxe/enum": "^0.2.0"
"eclipxe/enum": "^0.2.7"
},
"require-dev": {
"ext-json": "*",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^10.5.45"
},
"prefer-stable": true,
"autoload": {
Expand Down Expand Up @@ -60,15 +61,15 @@
"@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",
"@php tools/php-cs-fixer fix --verbose",
"@php tools/phpcbf --colors -sp"
],
"dev:test": [
"@php vendor/bin/phpunit --testdox --verbose --stop-on-failure",
"@php vendor/bin/phpunit --testdox --stop-on-failure",
"@php tools/phpstan analyse --no-progress --verbose"
]
},
Expand Down
23 changes: 23 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@ versión, aunque sí su incorporación en la rama principal de trabajo. Generalm

## Listado de cambios

### Versión 1.3.0 2025-04-12

- Se mejoran las declaraciones de tipos.
- Se elimina la compatiblidad con PHP 7.3, PHP 7.4 y PHP 8.0.
- Se actualiza la acción de GitHub a `Update to SonarSource/sonarqube-scan-action@v5`.

### Versión 1.2.3 2025-03-30

Se corrigieron los problemas asociados a la compatibilidad de PHP 8.4.

- Se agregó explícitamente el operador de tipos *nullable* `?`.
- Se actualizó la dependencia `eclipxe/enum` a una versión compatible con PHP 8.4.

Se actualiza el año de licencia a 2025.

Se hicieron cambios menores al código sugeridos por PHPStan y PSalm.

Adicionalmente, se hacen los siguientes cambios internos:

- Se agrega PHP 8.4 a la matriz de pruebas del flujo de trabajo `build`.
- Se ejecuta la mayoría de los trabajos de los flujos de trabajo usando PHP 8.4.
- Se actualizan las herramientas de desarrollo.

### Versión 1.2.2 2024-06-06

Se corrigió el problema de no crear correctamente el número de serie cuando incluía caracteres en mayúsculas.
Expand Down
20 changes: 10 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
bootstrap="tests/bootstrap.php"
colors="true"
>
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<source>
<include>
<directory>src</directory>
</include>
</source>
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
16 changes: 7 additions & 9 deletions src/Certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ class Certificate
use LocalFileOpenTrait;

/** @var string PEM contents including headers */
private $pem;
private string $pem;

/** @var string RFC as parsed from subject/x500UniqueIdentifier */
private $rfc;
private string $rfc;

/** @var string Legal name as parsed from subject/x500UniqueIdentifier */
private $legalName;
private string $legalName;

/** @var SerialNumber|null Parsed serial number */
private $serialNumber;
private ?SerialNumber $serialNumber = null;

/** @var PublicKey|null Parsed public key */
private $publicKey;
private ?PublicKey $publicKey = null;

/**
* Certificate constructor
Expand Down Expand Up @@ -59,7 +59,6 @@ public function __construct(string $contents)
* Convert X.509 DER base64 or X.509 DER to X.509 PEM
*
* @param string $contents can be a certificate format X.509 DER or X.509 DER base64
* @return string
*/
public static function convertDerToPem(string $contents): string
{
Expand All @@ -77,7 +76,6 @@ public static function convertDerToPem(string $contents): string
* The content file can be a certificate format X.509 PEM, X.509 DER or X.509 DER base64
*
* @param string $filename must be a local file (without scheme or file:// scheme)
* @return Certificate
*/
public static function openFile(string $filename): self
{
Expand Down Expand Up @@ -230,12 +228,12 @@ public function satType(): SatTypeEnum
return SatTypeEnum::csd();
}

public function validOn(DateTimeImmutable $datetime = null): bool
public function validOn(?DateTimeImmutable $datetime = null): bool
{
if (null === $datetime) {
$datetime = new DateTimeImmutable();
}
return ($datetime >= $this->validFromDateTime() && $datetime <= $this->validToDateTime());
return $datetime >= $this->validFromDateTime() && $datetime <= $this->validToDateTime();
}

protected function createSerialNumber(string $hexadecimal, string $decimal): SerialNumber
Expand Down
18 changes: 2 additions & 16 deletions src/Credential.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@

class Credential
{
/** @var Certificate */
private $certificate;
private readonly Certificate $certificate;

/** @var PrivateKey */
private $privateKey;
private readonly PrivateKey $privateKey;

/**
* Credential constructor
*
* @param Certificate $certificate
* @param PrivateKey $privateKey
* @throws UnexpectedValueException Certificate does not belong to private key
*/
public function __construct(Certificate $certificate, PrivateKey $privateKey)
Expand All @@ -35,11 +31,6 @@ public function __construct(Certificate $certificate, PrivateKey $privateKey)
*
* The certificate content can be X.509 PEM, X.509 DER or X.509 DER base64
* The private key content can be PKCS#8 DER, PKCS#8 PEM or PKCS#5 PEM
*
* @param string $certificateContents
* @param string $privateKeyContents
* @param string $passPhrase
* @return self
*/
public static function create(string $certificateContents, string $privateKeyContents, string $passPhrase): self
{
Expand All @@ -54,11 +45,6 @@ public static function create(string $certificateContents, string $privateKeyCon
* File paths must be local, can have no schema or file:// schema
* The certificate file content can be X.509 PEM, X.509 DER or X.509 DER base64
* The private key file content can be PKCS#8 DER, PKCS#8 PEM or PKCS#5 PEM
*
* @param string $certificateFile
* @param string $privateKeyFile
* @param string $passPhrase
* @return self
*/
public static function openFiles(string $certificateFile, string $privateKeyFile, string $passPhrase): self
{
Expand Down
8 changes: 2 additions & 6 deletions src/Internal/BaseConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
*/
class BaseConverter
{
/** @var BaseConverterSequence */
private $sequence;

public function __construct(BaseConverterSequence $sequence)
public function __construct(private readonly BaseConverterSequence $sequence)
{
$this->sequence = $sequence;
}

public static function createBase36(): self
Expand Down Expand Up @@ -54,7 +50,7 @@ public function convert(string $input, int $frombase, int $tobase): string
$input = $originalSequence[0]; // use zero as input
}
$chars = substr($originalSequence, 0, $frombase);
if (! boolval(preg_match("/^[$chars]+$/", $input))) {
if (! preg_match("/^[$chars]+$/", $input)) {
throw new UnexpectedValueException('The number to convert contains invalid characters');
}

Expand Down
Loading