Skip to content

Conversation

@absumo
Copy link
Contributor

@absumo absumo commented Aug 5, 2025

Summary by Sourcery

Add a new form type for selecting Belgian postcodes with municipality names, backed by a generated dataset and Symfony Intl.

New Features:

  • Introduce BelgiumPostCodeType form type with a callback transformer and Intl-based choice loader
  • Add BelgiumPostCodes resource bundle and a generated dataset file containing postcode and municipality mappings
  • Create a BelgiumPostCode value object to encapsulate postcode and municipality

Build:

  • Add symfony/intl as a dependency

Documentation:

  • Add translation entries for form label ‘Postcode and municipality’ and invalid message

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 5, 2025

Reviewer's Guide

This PR adds a new Symfony form type for selecting Belgian postcodes and municipalities by introducing a value object, model transformer, Intl ResourceBundle loader, and raw dataset, along with service registration, updated dependencies, and relevant translations.

Entity relationship diagram for BelgiumPostCode value object

erDiagram
    BELGIUM_POST_CODE {
        string postcode
        string municipality
    }
Loading

Class diagram for new BelgiumPostCode form type and related classes

classDiagram
    class BelgiumPostCodeType {
        +buildForm(FormBuilderInterface, array): void
        +configureOptions(OptionsResolver): void
        +getParent(): ?string
        +getBlockPrefix(): string
    }
    class BelgiumPostCodes {
        +static getNames(): array<string, string>
        #static getPath(): string
    }
    class BelgiumPostCode {
        +string postcode
        +string municipality
        +__construct(string postcode, string municipality)
    }
    BelgiumPostCodeType --> BelgiumPostCode : uses
    BelgiumPostCodeType --> BelgiumPostCodes : uses
    BelgiumPostCodes --|> ResourceBundle
Loading

File-Level Changes

Change Details Files
Introduced new BelgiumPostCode form type and support classes
  • Implemented BelgiumPostCodeType extending ChoiceType with a model transformer and custom choice loader
  • Created BelgiumPostCodes ResourceBundle to read postcode data
  • Defined immutable BelgiumPostCode value object for pairing postcode and municipality
src/Form/Type/BelgiumPostCodeType.php
src/Intl/BelgiumPostCodes.php
src/ValueObject/BelgiumPostCode.php
Added raw Belgian postcode dataset
  • Generated nl.php containing all postcode–municipality entries as a PHP array
src/Intl/Resources/data/belgiumpostcodes/nl.php
Registered new form type in service container
  • Imported BelgiumPostCodeType in services.php
  • Declared service and tagged it with form.type alias 'sumoBelgiumPostCode'
config/services.php
Updated dependencies and added translation keys
  • Added symfony/intl requirement to composer.json
  • Added 'Postcode and municipality' label in messages.en.yml and messages.nl.yml
  • Added 'Please select a valid postcode.' in validators en and nl translation files
composer.json
translations/messages.en.yml
translations/messages.nl.yml
translations/validators.en.yml
translations/validators.nl.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @absumo - I've reviewed your changes - here's some feedback:

  • In services.php, you're using the same service id (framework.file_type) for both FileType and BelgiumPostCodeType—use a unique id for the new form type.
  • BelgiumPostCodes::getNames currently hard-codes the locale to 'nl'; consider using the application’s current locale (Intl::getLocale() or Symfony’s locale) to support multiple languages.
  • The generated data file for postcodes is extremely large and loaded in memory all at once; consider moving to a more efficient lazy-loaded or external resource to avoid potential performance and repository bloat.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In services.php, you're using the same service id (`framework.file_type`) for both FileType and BelgiumPostCodeType—use a unique id for the new form type.
- BelgiumPostCodes::getNames currently hard-codes the locale to 'nl'; consider using the application’s current locale (Intl::getLocale() or Symfony’s locale) to support multiple languages.
- The generated data file for postcodes is extremely large and loaded in memory all at once; consider moving to a more efficient lazy-loaded or external resource to avoid potential performance and repository bloat.

## Individual Comments

### Comment 1
<location> `src/Form/Type/BelgiumPostCodeType.php:57` </location>
<code_context>
+            'choice_translation_domain' => false,
+            'invalid_message' => 'Please select a valid postcode.',
+            'placeholder' => '',
+            'autocomplete' => true,
+            'label' => 'Postcode and municipality',
+        ]);
</code_context>

<issue_to_address>
The 'autocomplete' option is not a standard FormType option.

To set an HTML autocomplete attribute, use the 'attr' option: ['attr' => ['autocomplete' => 'on']]. The current 'autocomplete' option will be ignored by Symfony forms.
</issue_to_address>

### Comment 2
<location> `src/Intl/BelgiumPostCodes.php:14` </location>
<code_context>
+     */
+    public static function getNames(): array
+    {
+        return self::readEntry(['Names'], 'nl', false);
+    }
+
</code_context>

<issue_to_address>
Hardcoding 'nl' locale limits flexibility.

Consider making the locale parameter configurable or using the current request locale to support multiple languages.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    /**
     * @return array<string, string>
     */
    public static function getNames(): array
    {
        return self::readEntry(['Names'], 'nl', false);
    }
=======
    /**
     * @param string|null $locale
     * @return array<string, string>
     */
    public static function getNames(?string $locale = null): array
    {
        if ($locale === null) {
            $locale = \Locale::getDefault();
        }
        return self::readEntry(['Names'], $locale, false);
    }
>>>>>>> REPLACE

</suggested_fix>

### Comment 3
<location> `src/Intl/Resources/data/belgiumpostcodes/nl.php:18` </location>
<code_context>
+    'Names' => [
+        "0612Sinterklaas" => "0612 - Sinterklaas",
+        "1000Brussel" => "1000 - Brussel",
+        "1005Verenigde Vergadering van de Gemeenschappelijke " => "1005 - Verenigde Vergadering van de Gemeenschappelijke ",
+        "1006Raad van de Vlaamse Gemeenschapscommissie" => "1006 - Raad van de Vlaamse Gemeenschapscommissie",
+        "1007Assemblée de la Commission Communautaire Française" => "1007 - Assemblée de la Commission Communautaire Française",
</code_context>

<issue_to_address>
Trailing space in key and value may cause lookup inconsistencies.

Please check if the trailing spaces in both the key and value are intentional and match the data source, as they may cause subtle lookup bugs.
</issue_to_address>

### Comment 4
<location> `src/Intl/Resources/data/belgiumpostcodes/nl.php:1951` </location>
<code_context>
+        "7090Braine-le-Comte" => "7090 - Braine-le-Comte",
+        "7090Hennuyères" => "7090 - Hennuyères",
+        "7090Henripont" => "7090 - Henripont",
+        "7090Petit-R�ulx-lez-Braine" => "7090 - Petit-R�ulx-lez-Braine",
+        "7090Ronquières" => "7090 - Ronquières",
+        "7090Steenkerque" => "7090 - Steenkerque",
</code_context>

<issue_to_address>
Non-ASCII character encoding issue in 'Petit-R�ulx-lez-Braine'.

The character '�' in this entry may cause lookup or display problems. Please check and fix the encoding here and in similar cases.
</issue_to_address>

### Comment 5
<location> `src/Intl/Resources/data/belgiumpostcodes/nl.php:1997` </location>
<code_context>
+        "7181Arquennes" => "7181 - Arquennes",
+        "7181Familleureux" => "7181 - Familleureux",
+        "7181Feluy" => "7181 - Feluy",
+        "7181Petit-R�ulx-lez-Nivelles" => "7181 - Petit-R�ulx-lez-Nivelles",
+        "7190Écaussinnes-d'Enghien" => "7190 - Écaussinnes-d'Enghien",
+        "7190Marche-lez-Écaussinnes" => "7190 - Marche-lez-Écaussinnes",
</code_context>

<issue_to_address>
Encoding issue in 'Petit-R�ulx-lez-Nivelles'.

Please correct the encoding for 'Petit-R�ulx-lez-Nivelles' to maintain data integrity.
</issue_to_address>

### Comment 6
<location> `src/Intl/Resources/data/belgiumpostcodes/nl.php:2021` </location>
<code_context>
+        "7340Wasmes" => "7340 - Wasmes",
+        "7350Hainin" => "7350 - Hainin",
+        "7350Hensies" => "7350 - Hensies",
+        "7350Montr�ul-sur-Haine" => "7350 - Montr�ul-sur-Haine",
+        "7350Thulin" => "7350 - Thulin",
+        "7370Blaugies" => "7370 - Blaugies",
</code_context>

<issue_to_address>
Encoding issue in 'Montr�ul-sur-Haine'.

The name includes a non-standard character ('�'); please check the encoding and correct it.
</issue_to_address>

### Comment 7
<location> `src/Intl/Resources/data/belgiumpostcodes/nl.php:2205` </location>
<code_context>
+        "7911Frasnes-lez-Buissenal" => "7911 - Frasnes-lez-Buissenal",
+        "7911Hacquegnies" => "7911 - Hacquegnies",
+        "7911Herquegies" => "7911 - Herquegies",
+        "7911Montr�ul-au-Bois" => "7911 - Montr�ul-au-Bois",
+        "7911Moustier" => "7911 - Moustier",
+        "7911Oeudeghien" => "7911 - Oeudeghien",
</code_context>

<issue_to_address>
Encoding issue in 'Montr�ul-au-Bois'.

Please correct the encoding of 'Montr�ul-au-Bois' to prevent lookup or display problems.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@absumo absumo force-pushed the 39-autocomplete-postcodes branch from d88584d to b66fb14 Compare August 11, 2025 12:19
@tijsverkoyen
Copy link
Member

@absumo schrijf misschien nog docs. En dan mag je mergen.

@absumo absumo merged commit 9d597b7 into master Aug 13, 2025
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.

3 participants