Siret.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Service\Utils;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Contracts\HttpClient\HttpClientInterface;
  6. /**
  7. * Class Siret : méthodes d'aide pour la gestion de numéro de Siret.
  8. * @package App\Service\Utils
  9. */
  10. class Siret
  11. {
  12. private HttpClientInterface $clientSiret;
  13. public function __construct(
  14. HttpClientInterface $siret_checking
  15. )
  16. {
  17. $this->clientSiret = $siret_checking;
  18. }
  19. /**
  20. * Vérifie si le numéro de Siret passé en paramètre est valide
  21. * @param string $siret
  22. * @return bool
  23. * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
  24. * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
  25. * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
  26. * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
  27. * @see SiretTest::testIsSiretIsCorrect()
  28. */
  29. public function isSiretIsCorrect(string $siret): bool {
  30. $response = $this->clientSiret->request('GET', $siret);
  31. return $response->getStatusCode() === Response::HTTP_OK;
  32. }
  33. }