AbstractDumper.php 990 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the Geocoder package.
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * @license MIT License
  9. */
  10. namespace Geocoder\Dumper;
  11. use Geocoder\Location;
  12. abstract class AbstractDumper
  13. {
  14. /**
  15. * @param Location $address
  16. *
  17. * @return string
  18. */
  19. protected function formatName(Location $address): string
  20. {
  21. $name = [];
  22. $array = $address->toArray();
  23. foreach (['streetNumber', 'streetName', 'postalCode', 'locality'] as $attr) {
  24. $name[] = $array[$attr];
  25. }
  26. if (isset($array['adminLevels'][2])) {
  27. $name[] = $array['adminLevels'][2]['name'];
  28. }
  29. if (isset($array['adminLevels'][1])) {
  30. $name[] = $array['adminLevels'][1]['name'];
  31. }
  32. $name[] = $array['country'];
  33. return implode(', ', array_filter($name));
  34. }
  35. }