From 4753fe9ffa03e62987a7a64a82375cff71ca8163 Mon Sep 17 00:00:00 2001 From: Carlos C Soto Date: Thu, 7 Mar 2024 20:26:53 -0600 Subject: [PATCH 1/4] Update version table --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1678289..d0240cd 100644 --- a/README.md +++ b/README.md @@ -155,10 +155,11 @@ 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, 8.3 | 2023-12-13 | -| 2.0.0 | 8.2, 8.3 | 2024-03-07 | +| Versión | PHP | Nota | +|---------|----------|-----------------------------------| +| 1.0.0 | 8.2, 8.3 | 2023-12-13 Fuera de mantenimiento | +| 2.0.0 | 8.2, 8.3 | 2024-03-07 Fuera de mantenimiento | +| 3.0.0 | 8.2, 8.3 | 2024-03-07 | ## Contribuciones From e63a27f747c3a599766aead4328b12e062ab7134 Mon Sep 17 00:00:00 2001 From: Carlos C Soto Date: Thu, 7 Mar 2024 20:27:29 -0600 Subject: [PATCH 2/4] Improve code using array shift --- src/App/SatPysScraper.php | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/App/SatPysScraper.php b/src/App/SatPysScraper.php index 8fed8c1..3c6c9c3 100644 --- a/src/App/SatPysScraper.php +++ b/src/App/SatPysScraper.php @@ -113,30 +113,22 @@ public function processArguments(string ...$arguments): array $quiet = false; $sort = 'key'; - $argumentsCount = count($arguments); - for ($i = 0; $i < $argumentsCount; $i++) { - $argument = $arguments[$i]; + while ([] !== $arguments) { + $argument = (string) array_shift($arguments); 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)) { - $sort = strval($arguments[++$i] ?? ''); + $xml = (string) array_shift($arguments); + } elseif (in_array($argument, ['--json', '-j'], true)) { + $json = (string) array_shift($arguments); + } elseif (in_array($argument, ['--sort', '-s'], true)) { + $sort = (string) array_shift($arguments); if (! in_array($sort, ['key', 'name'])) { throw new ArgumentException(sprintf('Invalid sort "%s"', $sort)); } - continue; - } - if (in_array($argument, ['--quiet', '-q'], true)) { + } elseif (in_array($argument, ['--quiet', '-q'], true)) { $quiet = true; - continue; + } else { + throw new ArgumentException(sprintf('Invalid argument "%s"', $argument)); } - - throw new ArgumentException(sprintf('Invalid argument "%s"', $argument)); } if ('' === $xml && '' === $json) { From a3a4d6fce793e7d40270fde0cc5f25134415f82d Mon Sep 17 00:00:00 2001 From: Carlos C Soto Date: Thu, 7 Mar 2024 20:27:38 -0600 Subject: [PATCH 3/4] Add test for printer generator --- .../Unit/App/PrinterGeneratorTrackerTest.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/Unit/App/PrinterGeneratorTrackerTest.php diff --git a/tests/Unit/App/PrinterGeneratorTrackerTest.php b/tests/Unit/App/PrinterGeneratorTrackerTest.php new file mode 100644 index 0000000..e5b6882 --- /dev/null +++ b/tests/Unit/App/PrinterGeneratorTrackerTest.php @@ -0,0 +1,59 @@ +expectOutputRegex('/^Obteniendo tipos/'); + $printer->boot(); + } + + public function testType(): void + { + $printer = new PrinterGeneratorTracker(); + $type = new Type('1', 'Foo'); + + $this->expectOutputRegex('/^Obteniendo segmentos para el tipo 1 - Foo/'); + $printer->type($type); + } + + public function testSegment(): void + { + $printer = new PrinterGeneratorTracker(); + $segment = new Segment('99', 'Foo'); + + $this->expectOutputRegex('/^\tObteniendo familias para el segmento 99 - Foo/'); + $printer->segment($segment); + } + + public function testFamily(): void + { + $printer = new PrinterGeneratorTracker(); + $family = new Family('9999', 'Foo'); + + $this->expectOutputRegex('/^\t\tObteniendo clases para la familia 9999 - Foo/'); + $printer->family($family); + } + + public function testClass(): void + { + $printer = new PrinterGeneratorTracker(); + $classification = new Classification('999999', 'Foo'); + + $this->expectOutputString(''); + $printer->class($classification); + } +} From b7f249da2c27d86812545011dcf3bc4afda4529a Mon Sep 17 00:00:00 2001 From: Carlos C Soto Date: Thu, 7 Mar 2024 20:29:40 -0600 Subject: [PATCH 4/4] Update changelog vefore release --- docs/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a285f33..8fedec2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -14,6 +14,8 @@ versión, aunque sí su incorporación en la rama principal de trabajo. Generalm ### Versión 3.0.0 2023-03-07 - Se cambia el método `SatPysScraper::run()` para una mejor inyección de dependencias y capacidad de pruebas. +- Se introduce una excepción dedicada para los errores de procesamiento de argumentos. +- Se cambia la forma de procesar los argumentos para usar `array_shift`. ### Versión 2.0.0 2023-03-07