Skip to content

Conversation

@norkunas
Copy link
Member

@norkunas norkunas commented Dec 22, 2025

Closes #351

Summary by CodeRabbit

  • New Features

    • Support for Stringable address objects in geocoding; stringable addresses are accepted and normalized to strings before geocoding.
  • Bug Fixes

    • Improved handling of address values: non-stringable or empty addresses are skipped to avoid spurious geocode attempts.
    • Error messages now report class names more consistently.
  • Tests

    • Added functional tests and fixtures covering stringable-address entities.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 22, 2025

Warning

Rate limit exceeded

@norkunas has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 19 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d999bfd and f3f2931.

📒 Files selected for processing (5)
  • src/Doctrine/ORM/GeocoderListener.php
  • src/Mapping/Driver/AttributeDriver.php
  • tests/Functional/Fixtures/Entity/DummyWithStringableGetter.php
  • tests/Functional/Fixtures/Entity/StringableAddress.php
  • tests/Functional/GeocoderListenerTest.php

Walkthrough

Geocoding now accepts objects implementing Stringable: addresses from getters or embedded fields are cast to string before building GeocodeQuery. Tests and fixtures for a Stringable address type were added. Minor class-name formatting change in AttributeDriver error message.

Changes

Cohort / File(s) Summary
Geocoder listener
src/Doctrine/ORM/GeocoderListener.php
Accept objects implementing \Stringable as addresses; skip non-stringable objects, cast accepted addresses to string and use that string when creating the GeocodeQuery; use ::class for entity class retrieval when recomputing change sets.
Mapping driver message
src/Mapping/Driver/AttributeDriver.php
Adjusted exception message to reference the class using $object::class instead of get_class($object).
Test fixtures (entities)
tests/Functional/Fixtures/Entity/StringableAddress.php, tests/Functional/Fixtures/Entity/DummyWithStringableGetter.php
Added StringableAddress embeddable implementing \Stringable and DummyWithStringableGetter entity with embedded StringableAddress and an address getter annotated for geocoding.
Functional tests
tests/Functional/GeocoderListenerTest.php
Added testPersistForStringableGetter() to verify persisting an entity with a stringable address triggers geocoding and populates latitude/longitude.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review focus:
    • GeocoderListener.php: ensure stringable detection and casting occur before GeocodeQuery creation and that empty-string cases are handled correctly.
    • AttributeDriver.php: verify message change is purely cosmetic and uses correct class reference.
    • New tests/fixtures: ensure annotations/attributes match mapping expectations and the test environment builds the schema correctly.

Possibly related PRs

Poem

🐰 I nibble a string, then hop with glee,

My address becomes text for the map to see,
No longer trapped, objects sing out clear,
Latitude and longitude soon appear 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: allowing stringable objects to be used for geocoding addresses, which matches the primary objective.
Linked Issues check ✅ Passed The pull request successfully implements the requirement from issue #351 to accept stringable objects implementing __toString() or Stringable interface for geocoding.
Out of Scope Changes check ✅ Passed All changes are directly related to enabling stringable object support for geocoding; no unrelated modifications detected.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/Doctrine/ORM/GeocoderListener.php (1)

95-99: LGTM! Consider edge case with empty Stringable result.

The type check and string cast correctly enable Stringable support. Note that empty($address) won't catch a Stringable object whose __toString() returns an empty string (since objects are truthy). If this edge case matters, you could cast before the empty check:

🔎 Optional refinement
-        if (empty($address) || (!is_string($address) && !$address instanceof \Stringable)) {
+        if (!is_string($address) && !$address instanceof \Stringable) {
+            return;
+        }
+
+        $addressString = (string) $address;
+        if ('' === $addressString) {
             return;
         }

-        $results = $this->geocoder->geocodeQuery(GeocodeQuery::create((string) $address));
+        $results = $this->geocoder->geocodeQuery(GeocodeQuery::create($addressString));
tests/Functional/Fixtures/Entity/DummyWithStringableGetter.php (2)

43-56: Duplicate #[Address] attribute on property and getter.

The #[Address] attribute is applied to both the $address property (line 44) and the getAddress() method (line 52). This differs from the pattern in DummyWithAddressGetter.php where #[Address] is only on the getter. The duplicate attribute may be redundant or could cause unexpected behavior in the metadata driver.

Consider removing #[Address] from the property since the getter is the intended source:

🔎 Proposed fix
     #[Embedded]
-    #[Address]
     public StringableAddress $address;

30-41: Consider adding type hints for properties.

For consistency and improved static analysis, consider adding explicit type hints to $latitude and $longitude properties (e.g., ?float).

🔎 Optional improvement
     #[Column]
     #[Latitude]
-    public $latitude;
+    public ?float $latitude = null;

     #[Column]
     #[Longitude]
-    public $longitude;
+    public ?float $longitude = null;
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60da2c7 and e9139ee.

📒 Files selected for processing (4)
  • src/Doctrine/ORM/GeocoderListener.php
  • tests/Functional/Fixtures/Entity/DummyWithStringableGetter.php
  • tests/Functional/Fixtures/Entity/StringableAddress.php
  • tests/Functional/GeocoderListenerTest.php
🧰 Additional context used
🧬 Code graph analysis (2)
src/Doctrine/ORM/GeocoderListener.php (1)
tests/Mapping/Driver/Fixtures/DummyWithAddressGetter.php (1)
  • Geocodeable (18-26)
tests/Functional/GeocoderListenerTest.php (1)
tests/Functional/Fixtures/Entity/DummyWithStringableGetter.php (2)
  • Entity (26-57)
  • setAddress (47-50)
🔇 Additional comments (3)
tests/Functional/Fixtures/Entity/StringableAddress.php (1)

18-31: LGTM!

Clean implementation of a Stringable value object. The use of constructor property promotion with Doctrine attributes and proper implementation of the \Stringable interface follows PHP 8 best practices.

tests/Functional/GeocoderListenerTest.php (2)

182-211: LGTM!

The test correctly validates the Stringable address path. It follows the same structure as existing tests and properly verifies that geocoding occurs for entities with Stringable address getters.


20-21: Imports are correctly added.

The new fixture imports align with the test additions.

@norkunas norkunas force-pushed the stringable-getter branch 2 times, most recently from 4dfb6c0 to d999bfd Compare December 22, 2025 05:16
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/Functional/GeocoderListenerTest.php (1)

182-211: Consider adding update scenario for test consistency.

The test correctly validates that stringable addresses can be geocoded. However, both testPersistForProperty and testPersistForGetter include an additional check: they clone the entity, change the address, flush again, and assert that the coordinates have changed. This verifies that address changes trigger re-geocoding.

For consistency and complete coverage, consider adding the same update scenario to this test.

🔎 Suggested addition for update scenario
     $em->persist($dummy);
     $em->flush();
 
     self::assertNotNull($dummy->latitude);
     self::assertNotNull($dummy->longitude);
+
+    $clone = clone $dummy;
+    $dummy->setAddress(new StringableAddress('Paris, France'));
+
+    $em->persist($dummy);
+    $em->flush();
+
+    self::assertNotEquals($clone->latitude, $dummy->latitude);
+    self::assertNotEquals($clone->longitude, $dummy->longitude);
 }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9139ee and d999bfd.

📒 Files selected for processing (5)
  • src/Doctrine/ORM/GeocoderListener.php
  • src/Mapping/Driver/AttributeDriver.php
  • tests/Functional/Fixtures/Entity/DummyWithStringableGetter.php
  • tests/Functional/Fixtures/Entity/StringableAddress.php
  • tests/Functional/GeocoderListenerTest.php
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/Doctrine/ORM/GeocoderListener.php
  • tests/Functional/Fixtures/Entity/DummyWithStringableGetter.php
  • tests/Functional/Fixtures/Entity/StringableAddress.php
🧰 Additional context used
🧬 Code graph analysis (2)
tests/Functional/GeocoderListenerTest.php (1)
tests/Functional/Fixtures/Entity/DummyWithStringableGetter.php (2)
  • Entity (26-56)
  • setAddress (46-49)
src/Mapping/Driver/AttributeDriver.php (1)
src/Mapping/Exception/MappingException.php (1)
  • MappingException (18-20)
🔇 Additional comments (2)
src/Mapping/Driver/AttributeDriver.php (1)

43-43: LGTM! Modern PHP syntax for class name resolution.

The change from get_class($object) to $object::class is a good modernization. This syntax is more concise and consistent with the changes elsewhere in the codebase.

tests/Functional/GeocoderListenerTest.php (1)

20-21: LGTM! Imports are correct and well-organized.

The new imports for the stringable address test fixtures are properly ordered and follow the existing conventions.

@norkunas norkunas merged commit 80d51ce into geocoder-php:master Dec 22, 2025
16 checks passed
@norkunas norkunas deleted the stringable-getter branch December 22, 2025 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow stringable object to be used to geocode address

1 participant