InvalidServerResponse.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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\Exception;
  11. /**
  12. * When the geocoder server returns something that we cannot process.
  13. *
  14. * @author Tobias Nyholm <tobias.nyholm@gmail.com>
  15. */
  16. final class InvalidServerResponse extends \RuntimeException implements Exception
  17. {
  18. /**
  19. * @param string $query
  20. * @param int $code
  21. *
  22. * @return InvalidServerResponse
  23. */
  24. public static function create(string $query, int $code = 0): self
  25. {
  26. return new self(sprintf('The geocoder server returned an invalid response (%d) for query "%s". We could not parse it.', $code, $query));
  27. }
  28. /**
  29. * @param string $query
  30. *
  31. * @return InvalidServerResponse
  32. */
  33. public static function emptyResponse(string $query): self
  34. {
  35. return new self(sprintf('The geocoder server returned an empty response for query "%s".', $query));
  36. }
  37. }