From f0b552731dbf7a146f88c20ee78ef9f48e457094 Mon Sep 17 00:00:00 2001 From: Cody Reichert Date: Fri, 23 Feb 2024 14:55:48 -0600 Subject: [PATCH] Improve address display for undisclosed address When `internetAddressDisplay` is set to false, some feeds do not contain the city, state, or zip code as well. This prevents extra commas from being displayed when this address information is null. --- src/simply-rets-utils.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/simply-rets-utils.php b/src/simply-rets-utils.php index d6f0394..a6522da 100644 --- a/src/simply-rets-utils.php +++ b/src/simply-rets-utils.php @@ -121,12 +121,13 @@ public static function buildFullAddressString($listing) { $state = $listing->address->state; $zip = $listing->address->postalCode; - // A listing might have a null address if a flag like "Display - // address" is set to false. This just removes the comma in - // these cases, but the rest of the address remains the same. - $comma = $address ? ', ' : ''; + // When `internetAddressDisplay` is false, some feeds may also + // exclude city, state, and zip. This ensures that commas are + // only used when these fields exist. + $comma1 = ($address AND ($city OR $state OR $zip)) ? ', ' : ''; + $comma2 = $city ? ', ' : ''; - return $address . $comma . $city . ', ' . $state . ' ' . $zip; + return $address . $comma1 . $city . $comma2 . $state . ' ' . $zip; } /**