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
32 changes: 16 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
php-version: '8.5'
coverage: none
tools: composer-normalize
env:
Expand All @@ -35,11 +35,11 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
php-version: '8.5'
coverage: none
tools: composer-require-checker
env:
Expand All @@ -49,7 +49,7 @@ jobs:
shell: bash
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
uses: actions/cache@v6
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -64,11 +64,11 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
php-version: '8.5'
coverage: none
tools: cs2pr, phpcs
env:
Expand All @@ -81,11 +81,11 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
php-version: '8.5'
coverage: none
tools: cs2pr, php-cs-fixer
env:
Expand All @@ -98,11 +98,11 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
php-version: '8.5'
coverage: none
tools: composer:v2, phpstan
env:
Expand All @@ -112,7 +112,7 @@ jobs:
shell: bash
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
uses: actions/cache@v6
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -122,16 +122,16 @@ jobs:
- name: PHPStan
run: phpstan analyse --no-progress --verbose

tests:
phpunit:
name: PHP ${{ matrix.php-version }} on ${{ matrix.operating-system }}
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: ["windows-latest", "ubuntu-latest"]
php-version: ['8.2', '8.3', '8.4']
php-version: ['8.2', '8.3', '8.4', '8.5']
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -150,7 +150,7 @@ jobs:
shell: bash
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
uses: actions/cache@v6
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/sonarqube-cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

# Actions
# shivammathur/setup-php@v2 https://github.com/marketplace/actions/setup-php-action
# SonarSource/sonarqube-scan-action@v6 https://github.com/marketplace/actions/official-sonarqube-scan
# SonarSource/sonarqube-scan-action@v8 https://github.com/marketplace/actions/official-sonarqube-scan

jobs:

Expand All @@ -21,13 +21,13 @@ jobs:
exit 1
fi
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7
- name: Unshallow clone to provide blame information
run: git fetch --unshallow
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
php-version: '8.5'
coverage: xdebug
tools: composer:v2
- name: Install poppler-utils
Expand All @@ -38,7 +38,7 @@ jobs:
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
uses: actions/cache@v6
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -52,6 +52,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/sonarqube-scan-action@v6
uses: SonarSource/sonarqube-scan-action@v8
env:
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,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="composer-normalize" version="^2.48.2" installed="2.48.2" location="./tools/composer-normalize" copy="false"/>
<phar name="php-cs-fixer" version="^3.89.2" installed="3.89.2" location="./tools/php-cs-fixer" copy="false"/>
<phar name="phpcs" version="^3.13.5" installed="3.13.5" location="./tools/phpcs" copy="false"/>
<phar name="phpcbf" version="^3.13.5" installed="3.13.5" location="./tools/phpcbf" copy="false"/>
<phar name="phpstan" version="^2.1.31" installed="2.1.31" location="./tools/phpstan" copy="false"/>
<phar name="composer-normalize" version="^2.52.0" installed="2.52.0" location="./tools/composer-normalize" copy="false"/>
<phar name="php-cs-fixer" version="^3.95.25" installed="3.95.25" location="./tools/php-cs-fixer" copy="false"/>
<phar name="phpcs" version="^4.0.4" installed="4.0.4" location="./tools/phpcs" copy="false"/>
<phar name="phpcbf" version="^4.0.4" installed="4.0.4" location="./tools/phpcbf" copy="false"/>
<phar name="phpstan" version="^2.2.13" installed="2.2.13" location="./tools/phpstan" copy="false"/>
<phar name="composer-require-checker" version="^4.18.0" installed="4.18.0" location="./tools/composer-require-checker" copy="false"/>
</phive>
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) 2022 - 2025 PhpCfdi https://www.phpcfdi.com/
Copyright (c) 2022 - 2026 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
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^7.4",
"phpcfdi/rfc": "^1.1",
"guzzlehttp/guzzle": "^7.4 || ^8.3",
"phpcfdi/rfc": "^1.2",
"psr/http-client": "^1.0",
"symfony/css-selector": "^7.0",
"symfony/dom-crawler": "^7.0",
"symfony/process": "^7.0"
"symfony/css-selector": "^7.0 || ^8.0",
"symfony/dom-crawler": "^7.0 || ^8.0",
"symfony/process": "^7.0 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^11.5"
Expand Down Expand Up @@ -89,6 +89,6 @@
"dev:check-style": "DEV: search for code style errors using composer-normalize, php-cs-fixer and phpcs",
"dev:coverage": "DEV: run phpunit with xdebug and storage coverage in build/coverage/html/",
"dev:fix-style": "DEV: fix code style errors using composer-normalize, php-cs-fixer and phpcbf",
"dev:test": "DEV: run @dev:check-style, phpunit and phpstan"
"dev:test": "DEV: run @dev:check-style, phpunit, phpstan and composer-require-checker"
}
}
22 changes: 22 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ versión, aunque sí su incorporación en la rama principal de trabajo, generalm

## Listado de cambios

### Versión 0.2.1 2026-10-21

- Se asegura la compatibilidad con PHP 8.5.
- Se agrega compatibilidad con Symfony 8 (`symfony/css-selector`, `symfony/dom-crawler` y `symfony/process`).
- Se agrega compatibilidad con Guzzle 8, se mantiene la compatibilidad con Guzzle 7.
- Se actualiza la dependencia mínima de `phpcfdi/rfc` a la versión 1.2.
- Se corrige la lectura del RFC y del idCIF desde el PDF de la Constancia de Situación Fiscal cuando `pdftotext`
agrega el separador de página (`\f`) pegado al texto (encontrado en la versión de poppler-utils 26.10.0 para Mac).
- Se actualiza el año de la licencia a 2026.
- Se agrega un script funcional de ejemplo en `tests/bin/csf-info-pdf.php` que sirve para obtener la información en
formato JSON del archivo PDF dado.

Cambios al entorno de desarrollo:

- En los flujos de trabajo:
- Se actualizan las versiones de las acciones.
- Se agrega PHP 8.5 a la matriz de pruebas.
- Se ejecutan los trabajos en PHP 8.5.
- Se renombra el trabajo `tests` a `phpunit`.
- Se corrige la descripción de `composer dev:test` para incluir `composer-require-checker`.
- Se actualizan las herramientas de desarrollo.

### Versión 0.2.0 2025-11-10

- Se asegura la compatibilidad con PHP 8.3 y PHP 8.4.
Expand Down
2 changes: 1 addition & 1 deletion src/PdfReader/CsfExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(string $contents)
if ('' === $contents) {
throw new EmptyPdfContentException('Cannot read pdf contents.');
}
$this->lines = explode("\n", $contents);
$this->lines = preg_split('/[\n\f]/', $contents) ?: [];
}

public function getRfc(): ?string
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/PdfReader/CsfExtractor/GetCifIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public function test_obtains_cif(): void
$this->assertSame('12345678', $csfExtractor->getCifId());
}

public function test_obtains_cif_from_content_with_page_breaks(): void
{
$csfExtractor = new CsfExtractor($this->fileContents('csf-content-form-feed.txt'));
$this->assertSame('12345678', $csfExtractor->getCifId());
}

public function test_bad_content_returns_empty_rfc(): void
{
$csfExtractor = new CsfExtractor($this->fileContents('csf-bad-content.txt'));
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/PdfReader/CsfExtractor/GetRfcTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public function test_obtains_rfc(): void
$this->assertSame('DIM8701081LA', $csfExtractor->getRfc());
}

public function test_obtains_rfc_from_content_with_page_breaks(): void
{
$csfExtractor = new CsfExtractor($this->fileContents('csf-content-form-feed.txt'));
$this->assertSame('DIM8701081LA', $csfExtractor->getRfc());
}

public function test_bad_content_returns_empty_rfc(): void
{
$csfExtractor = new CsfExtractor($this->fileContents('csf-bad-content.txt'));
Expand Down
2 changes: 2 additions & 0 deletions tests/_files/csf-content-form-feed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONSTANCIA DE SITUACION FISCAL idCIF: 12345678
RFC: DIM8701081LA
107 changes: 107 additions & 0 deletions tests/bin/csf-info-pdf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

declare(strict_types=1);

use PhpCfdi\CsfScraper\Scraper;

require_once __DIR__ . '/../../vendor/autoload.php';

exit(call_user_func(new class (...($argv ?? [__FILE__])) {
public bool $debug;

public string $command;

/** @var list<string> */
public array $arguments;

public function __construct(string $command, string ...$arguments)
{
$this->debug = false;
$this->command = $command;
foreach ($arguments as $key => $value) {
if (in_array($value, ['-d', '--debug'])) {
$this->debug = true;
unset($arguments[$key]);
}
}
$this->arguments = array_values($arguments);
}

public function printHelp(): void
{
$command = basename($this->command);
echo implode(PHP_EOL, [
"$command - Obtiene la información con base en un archivo PDF",
'Sintaxis:',
" $command help|-h|--help",
" $command [-d|--debug] CSF-FILE",
'Argumentos:',
' --debug|-d Si se encuentra un error, muestra la excepción y todas las excepciones previas.',
' CSF-FILE Archivo PDF con la constancia de situación fiscal.',
'Salida:',
' Información extraída del sitio del SAT en formato JSON',
'Licencia y autoría:',
' La misma del proyecto https://github.com/phpcfdi/csf-scraper',
'Advertencia:',
' Este es un ejemplo de uso y este script pruebe cambiar en cualquier momento.',
' Use su propia implementación para evitar conflictos entre versiones.',
'',
'',
]);
}

public function __invoke(): int
{
if ([] !== array_intersect($this->arguments, ['--help', '-h', 'help'])) {
$this->printHelp();
return 0;
}
try {
$this->execute();
return 0;
} catch (Throwable $exception) {
if ($this->debug) {
for ($current = $exception; null !== $current; $current = $current->getPrevious()) {
$this->printError(sprintf('Exception (%s) %s', $exception::class, $exception->getMessage()));
$this->printError(sprintf('At %s(%s)', $exception->getFile(), $exception->getLine()));
$this->printError($exception->gettraceAsString());
}
} else {
$this->printError(sprintf('ERROR: %s', $exception->getMessage()));
}
return is_int($exception->getCode()) && $exception->getCode() > 0 ? $exception->getCode() : 1;
}
}

private function printError(string ...$messages): void
{
foreach ($messages as $message) {
file_put_contents('php://stderr', $message, FILE_APPEND);
file_put_contents('php://stderr', PHP_EOL, FILE_APPEND);
}
}

public function execute(): void
{
$filename = '';

$arguments = $this->arguments;
foreach ($arguments as $argument) {
if ('' === $filename) {
$filename = $argument;
} else {
throw new RuntimeException(sprintf('Unexpected argument "%s".', $argument));
}
}
if ('' === $filename) {
throw new RuntimeException('Expected argument CSF-FILE is not set.');
}
if (! file_exists($filename)) {
throw new RuntimeException(sprintf('File "%s" does not exists.', $filename));
}

$scraper = Scraper::create();
$person = $scraper->obtainFromPdfPath($filename);
echo json_encode($person, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE), PHP_EOL;
}
}));
Loading