Skip to content

Commit

Permalink
Merge pull request #1 from eclipxe13/version-2.0
Browse files Browse the repository at this point in the history
Corregir el nodo principal de xml y mejorar exportación (version 2.x)
  • Loading branch information
eclipxe13 authored Mar 7, 2024
2 parents 06a6342 + cb94325 commit 68ce6cf
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 93 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,24 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
tools: cs2pr, phive
tools: cs2pr, phpcs
env:
fail-fast: true
- name: Install phpcs
run: phive install phpcs --trust-gpg-keys 5E6DDE998AB73B8E
- name: Code style (phpcs)
run: tools/phpcs -q --report=checkstyle | cs2pr
run: phpcs -q --report=checkstyle | cs2pr

php-cs-fixer:
name: Code style (php-cs-fixer)
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -54,7 +52,7 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -67,7 +65,7 @@ jobs:
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -85,7 +83,7 @@ jobs:
php-versions: ['8.2', '8.3']
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -98,7 +96,7 @@ jobs:
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -28,7 +28,7 @@ jobs:
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Create code coverage
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@v3
uses: actions/upload-artifact@v4
with:
name: code-coverage
path: build/coverage
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Unshallow clone to provide blame information
run: git fetch --unshallow
- name: Setup PHP
Expand All @@ -86,15 +86,15 @@ jobs:
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
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: Obtain code coverage
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: code-coverage
path: build/coverage
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
php-versions: ['8.2', '8.3']
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -35,12 +35,12 @@ jobs:
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
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 --no-dev
- name: System test with PHP ${{ matrix.php-versions }}
run: php bin/sat-pys-scraper --format xml --sort key build/result.xml
run: php bin/sat-pys-scraper --json build/result.json --xml build/result.xml --sort key
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.41.1" installed="3.41.1" location="./tools/php-cs-fixer" copy="false"/>
<phar name="phpcs" version="^3.8.0" installed="3.8.0" location="./tools/phpcs" copy="false"/>
<phar name="phpcbf" version="^3.8.0" installed="3.8.0" location="./tools/phpcbf" copy="false"/>
<phar name="phpstan" version="^1.10.50" installed="1.10.50" location="./tools/phpstan" copy="false"/>
<phar name="composer-normalize" version="^2.41.1" installed="2.41.1" location="./tools/composer-normalize" copy="false"/>
<phar name="php-cs-fixer" version="^3.51.0" installed="3.51.0" location="./tools/php-cs-fixer" copy="false"/>
<phar name="phpcs" version="^3.9.0" installed="3.9.0" location="./tools/phpcs" copy="false"/>
<phar name="phpcbf" version="^3.9.0" installed="3.9.0" location="./tools/phpcbf" copy="false"/>
<phar name="phpstan" version="^1.10.60" installed="1.10.60" location="./tools/phpstan" copy="false"/>
<phar name="composer-normalize" version="^2.42.0" installed="2.42.0" location="./tools/composer-normalize" copy="false"/>
</phive>
6 changes: 3 additions & 3 deletions Docker.README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ docker run -it --rm --user="$(id -u):$(id -g)" \

# generar en un volumen
docker run -it --rm --user="$(id -u):$(id -g)" --volume="${PWD}:/local" \
sat-pys-scraper /local/output.xml
sat-pys-scraper --xml /local/output.xml


# pipe output to file (xml, sorted by key)
docker run -it --rm --user="$(id -u):$(id -g)" \
sat-pys-scraper - > output.xml
sat-pys-scraper --xml - > output.xml

# pipe output to file (json, sorted by name)
docker run -it --rm --user="$(id -u):$(id -g)" \
sat-pys-scraper - --format json --sort name > output.xml
sat-pys-scraper --json - --sort name > output.json
```
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,24 @@ sat-pys-scraper - Crea un archivo con la clasificación de productos y servicios
Sintaxis:
sat-pys-scraper help|-h|--help
sat-pys-scraper destination-file [--quiet|-q] [--format|-f FORMAT]
sat-pys-scraper [--quiet|-q] [--json|-j JSON_FILE] [--xml|-x XML_FILE]
Argumentos:
destination-file
Nombre del archivo XML para almacenar el resultado.
Si se usa "-" o se omite entonces el resultado se manda a la salida estándar
y se activa el modo de operación silencioso.
--format|-f FORMAT
Establece el formato de salida, default: xml, por el momento "xml" o "json".
--xml|-x XML_FILE
Establece el nombre de archivo, o "-" para la salida estándar, donde se envían
los datos generados en formato XML.
--json|-j JSON_FILE
Establece el nombre de archivo, o "-" para la salida estándar, donde se envían
los datos generados en formato JSON.
--sort|-s SORT
Establece el orden de elementos, default: key, se puede usar "key" o "name".
--quiet|-q
Modo de operación silencioso.
Notas:
Debe especificar al menos un argumento "--xml" o "--json", o ambos.
No se puede especificar "-" como salida de "--xml" y "--json" al mismo tiempo.
Acerca de:
Este script pertenece al proyecto https://github.com/phpcfdi/sat-pys-scraper
y mantiene la autoría y licencia de todo el proyecto.
Expand Down Expand Up @@ -151,9 +155,10 @@ Esta librería se mantendrá compatible con al menos la versión con
También utilizamos [Versionado Semántico 2.0.0](docs/SEMVER.md) por lo que puedes usar esta librería
sin temor a romper tu aplicación.

| Version | PHP | Notes |
|---------|-----|------------|
| 1.0.0 | 8.2 | 2023-12-13 |
| Version | PHP | Notes |
|---------|----------|------------|
| 1.0.0 | 8.2, 8.3 | 2023-12-13 |
| 2.0.0 | 8.2, 8.3 | 2024-03-07 |

## Contribuciones

Expand Down
10 changes: 10 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ versión, aunque sí su incorporación en la rama principal de trabajo. Generalm

## Listado de cambios

### Versión 2.0.0 2023-03-07

- Se corrige el nodo principal, el nombre correcto es `<pys>`.
- Se cambia el comando de ejecución `bin/sat-pys-scraper` para exportar a JSON y XML al mismo tiempo.

Otros cambios:

- Se utilizan las acciones de GitHub versión 4.
- Se actualizan las herramientas de desarrollo.

### Versión 1.0.0 2023-12-13

- Versión inicial.
70 changes: 39 additions & 31 deletions src/App/SatPysScraper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,24 @@ public function printHelp(): void
Sintaxis:
$command help|-h|--help
$command destination-file [--quiet|-q] [--format|-f FORMAT]
$command [--quiet|-q] [--json|-j JSON_FILE] [--xml|-x XML_FILE]
Argumentos:
destination-file
Nombre del archivo XML para almacenar el resultado.
Si se usa "-" o se omite entonces el resultado se manda a la salida estándar
y se activa el modo de operación silencioso.
--format|-f FORMAT
Establece el formato de salida, default: xml, por el momento "xml" o "json".
--xml|-x XML_FILE
Establece el nombre de archivo, o "-" para la salida estándar, donde se envían
los datos generados en formato XML.
--json|-j JSON_FILE
Establece el nombre de archivo, o "-" para la salida estándar, donde se envían
los datos generados en formato JSON.
--sort|-s SORT
Establece el orden de elementos, default: key, se puede usar "key" o "name".
--quiet|-q
Modo de operación silencioso.
Notas:
Debe especificar al menos un argumento "--xml" o "--json", o ambos.
No se puede especificar "-" como salida de "--xml" y "--json" al mismo tiempo.
Acerca de:
Este script pertenece al proyecto https://github.com/phpcfdi/sat-pys-scraper
y mantiene la autoría y licencia de todo el proyecto.
Expand Down Expand Up @@ -84,34 +88,35 @@ public function execute(): void
default => throw new Exception('Unrecognized sort argument'),
};

// create output
match ($arguments['format']) {
'xml' => $this->toXml($arguments['output'], $types),
'json' => $this->toJson($arguments['output'], $types),
default => throw new Exception('Unrecognized format argument'),
};
if ('' !== $arguments['xml']) {
$this->toXml($arguments['xml'], $types);
}
if ('' !== $arguments['json']) {
$this->toJson($arguments['json'], $types);
}
}

/**
* @return array{output: string, quiet: bool, format: string, sort: string}
* @return array{xml: string, json: string, quiet: bool, sort: string}
* @throws Exception
*/
public function processArguments(string ...$arguments): array
{
$arguments = array_values($arguments);
$output = '';
$xml = '';
$json = '';
$quiet = false;
$format = 'xml';
$sort = 'key';

$argumentsCount = count($arguments);
for ($i = 0; $i < $argumentsCount; $i++) {
$argument = $arguments[$i];
if (in_array($argument, ['--format', '-f'], true)) {
$format = strval($arguments[++$i] ?? '');
if (! in_array($format, ['xml', 'json'])) {
throw new Exception(sprintf('Invalid format "%s"', $format));
}
if (in_array($argument, ['--xml', '-x'], true)) {
$xml = strval($arguments[++$i] ?? '');
continue;
}
if (in_array($argument, ['--json', '-j'], true)) {
$json = strval($arguments[++$i] ?? '');
continue;
}
if (in_array($argument, ['--sort', '-s'], true)) {
Expand All @@ -125,26 +130,29 @@ public function processArguments(string ...$arguments): array
$quiet = true;
continue;
}
if ('' === $output) {
$output = $argument;
continue;
}

throw new Exception(sprintf('Invalid argument "%s"', $argument));
}

if ('' === $output) {
throw new Exception('Missing argument destination-file');
if ('' === $xml && '' === $json) {
throw new Exception('Did not specify --xml or --json arguments');
}
if ('-' === $xml && '-' === $json) {
throw new Exception('Cannot send --xml and --json result to standard output at the same time');
}
if ('-' === $xml) {
$xml = 'php://stdout';
$quiet = true;
}
if ('-' === $output) {
$output = 'php://stdout';
if ('-' === $json) {
$json = 'php://stdout';
$quiet = true;
}

return [
'output' => $output,
'xml' => $xml,
'json' => $json,
'quiet' => $quiet,
'format' => $format,
'sort' => $sort,
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/XmlExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function exportAsDocument(Data\Types $types): DOMDocument
$document = new DOMDocument();
$document->formatOutput = true;
/** @noinspection PhpUnhandledExceptionInspection */
$root = $document->createElement('psy');
$root = $document->createElement('pys');
$document->appendChild($root);

foreach ($types as $type) {
Expand Down
Loading

0 comments on commit 68ce6cf

Please sign in to comment.