Skip to content

Conversation

@parsilver
Copy link
Collaborator

Summary

  • Replace guzzlehttp/guzzle with farzai/transport for HTTP requests
  • Implement streaming in GazetteerConverter for O(1) memory complexity when processing large datasets
  • Modernize Symfony Console commands to use PHP 8 #[AsCommand] attributes
  • Improve error handling with proper file write checking
  • Update README documentation with better explanations

Changes

HTTP Client Migration

Replaced Guzzle with farzai/transport library for HTTP operations, simplifying the dependency chain.

Memory Optimization

Added generator-based streaming in GazetteerConverter to process large GeoNames files without loading everything into memory. Records are yielded one at a time for constant memory usage.

Code Modernization

  • Use #[AsCommand] attributes instead of static $defaultName and $defaultDescription properties
  • Add writeToHandle() methods with proper error checking in converters

Documentation

  • Add "How It Works" section explaining admin code resolution, memory-efficient processing, and automatic cleanup
  • Add "Error Handling" section with common error scenarios
  • Update MongoDB format documentation

New Tests

Added comprehensive unit tests:

  • tests/Helpers/MockHttpClient.php - HTTP client mocking
  • tests/Helpers/MockMongoDBClient.php - MongoDB client mocking
  • tests/Unit/Converter/GazetteerConverterTest.php
  • tests/Unit/Converter/PostalCodeConverterTest.php
  • tests/Unit/Converter/MongoDBConvertersProcessingTest.php
  • tests/Unit/Downloader/AbstractDownloaderTest.php
  • tests/Unit/Downloader/GazetteerDownloaderTest.php
  • tests/Unit/Downloader/GeonamesDownloaderTest.php

Test plan

  • Run composer test to verify all tests pass
  • Test postal code download: ./bin/geonames geonames:download TH
  • Test gazetteer download: ./bin/geonames geonames:gazetteer:download TH
  • Verify MongoDB export works (if MongoDB available)

- Migrate HTTP client from guzzlehttp/guzzle to farzai/transport
- Implement streaming in GazetteerConverter for O(1) memory complexity
- Use PHP 8 #[AsCommand] attributes for Symfony Console commands
- Add writeToHandle methods with proper error checking
- Update README with documentation improvements
- Add comprehensive unit tests for converters and downloaders
Broaden symfony/http-client constraint from ^7.3 to ^6.4 || ^7.0
to support PHP 8.1, as symfony/http-client 7.3+ requires PHP 8.2+.
Return null from createProgressBar when totalLines is 0 to avoid
LogicException in older Symfony Console versions that can't display
estimated time with zero max value.
@parsilver parsilver merged commit c7b4e4a into main Nov 26, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants