name: update-postal-formats description: Updates the $formats array in src/Validator.php from Wikipedia's postal codes list via bin/parse.php. Use when user says 'update formats', 'refresh postal codes', 'sync from Wikipedia', or 'formats are outdated'. Explains the parse.php workflow, MyAdmin dependency requirement, and how to paste output into Validator.php. Do NOT use for adding a single country manually — that is a direct edit to src/Validator.php.
update-postal-formats
Critical
bin/parse.phpcannot run standalone — it requiresgetcurlpage()and other functions from the parent MyAdmin environment. It must be run from within a MyAdmin install where the MyAdmin bootstrap resolves.- The script also queries the
country_tMySQL table via$GLOBALS['tf']->dbto fill in countries not found on Wikipedia. The MyAdmin DB connection must be active. - Never paste raw Wikipedia wikitext into
src/Validator.php— always run the parser to get properly converted PHP array entries. - Format symbols:
#= digit[0-9],@= letter[a-zA-Z]. The parser converts Wikipedia'sN→#andA→@automatically.
Instructions
Confirm the MyAdmin environment is available. Verify the parser script exists:
ls bin/parse.phpIf missing, the package is not installed — run
composer installfirst.Run the parser from the MyAdmin root. The script must be invoked from within the MyAdmin web context or via a bootstrap that initialises
$GLOBALS['tf']. Typical invocation:php bin/parse.phpThe script fetches
https://en.wikipedia.org/wiki/Special:Export/List_of_postal_codes, parses the wikitext table, merges withcountry_tDB rows, and prints sorted PHP array lines to stdout.Capture the output. Redirect to a temp file to review before pasting:
php bin/parse.php > /tmp/new_formats.phpEach output line looks like:
'US' => ['#####', '#####-####'], // United States 'AE' => [], // United Arab EmiratesVerify the output is not empty and contains known countries like
'US','CA','GB'.Replace the
$formatsarray body insrc/Validator.php. Opensrc/Validator.php. The array starts at:protected $formats = [ 'AD' => ['AD###'], // Andorraand ends with the closing
];before the next property or method. Replace everything betweenprotected $formats = [and its closing];with the parser output. Preserve the existing indentation style (tabs, not spaces — per.scrutinizer.yml).Verify the file is valid PHP.
php -l src/Validator.phpMust output
No syntax errors detected.Run the test suite.
vendor/bin/phpunit tests/ -vAll tests must pass. If a previously-passing country now fails, compare the old and new format strings for that country in
$formats.Review any countries with empty arrays
[]. An empty array means no postal system. Confirm intentional before committing — check Wikipedia directly for that ISO code if uncertain.
Examples
User says: "The postal formats are outdated, can you refresh them from Wikipedia?"
Actions taken:
- Confirmed
bin/parse.phpexists. - Ran
php bin/parse.php > /tmp/new_formats.php— output contained ~250 country entries. - Opened
src/Validator.php, locatedprotected $formats = [at line 35. - Replaced the array body with contents of
/tmp/new_formats.php. - Ran
php -l src/Validator.php→No syntax errors detected. - Ran
vendor/bin/phpunit tests/ -v→ all tests passed.
Result: $formats in src/Validator.php updated with current Wikipedia data. Example diff:
- 'AF' => ['####'], // Afghanistan
+ 'AF' => ['####', '####'], // Afghanistan, Notes: | 2011 ...
Common Issues
require /path/to/functions.inc.php: No such file or directory
- You are running
bin/parse.phpoutside the MyAdmin environment. The MyAdmin bootstrap must be available. Run from within a MyAdmin environment usingphp bin/parse.php.
Call to undefined function getcurlpage()
function_requirements('getcurlpage')failed to load the function. Verify the MyAdmin bootstrap loaded successfully and thatgetcurlpageexists in the MyAdmin function files.
Call to a member function query() on null (DB error)
$GLOBALS['tf']->dbis not initialised. The script requires an active MyAdmin DB connection. Run it through a MyAdmin bootstrap or CLI entry point that sets up$GLOBALS['tf'].
Empty output from bin/parse.php
- Wikipedia fetch failed or returned unexpected content. Check network access from the server to
en.wikipedia.org. Trycurl -s 'https://en.wikipedia.org/wiki/Special:Export/List_of_postal_codes' | head -50to verify the endpoint is reachable.
PHPUnit test failures after update
- A specific country's format changed. Compare the failing test's expected pattern against the new
$formatsentry. If Wikipedia's new data is correct, update the test intests/Detain/Tests/ZipZapper/ValidatorTest.php. If the new format looks wrong (e.g. a literal ISO code was not replaced), check theget_codes_from()logic inbin/parse.php— it replacesCCwith the ISO code,Nwith#, andAwith@.
Tabs vs spaces warning from linter
src/Validator.phpuses tab indentation (.scrutinizer.ymlenforces this). If your editor auto-converted to spaces, run:unexpand --first-only src/Validator.php > /tmp/v.php && mv /tmp/v.php src/Validator.php