Extract method to check if Guzzle is installed

This commit is contained in:
Andrea Marco Sartori 2023-02-25 20:38:35 +10:00
parent 308b15a5d8
commit 961b8a8278

View File

@ -2,7 +2,7 @@
namespace Cerbero\JsonParser\Concerns;
use Cerbero\JsonParser\Exceptions\SourceException;
use Cerbero\JsonParser\Exceptions\GuzzleRequiredException;
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\RequestInterface;
@ -18,15 +18,25 @@ trait GuzzleAware
* Abort if Guzzle is not loaded
*
* @return void
* @throws SourceException
* @throws GuzzleRequiredException
*/
protected function requireGuzzle(): void
{
if (!class_exists(Client::class)) {
throw SourceException::requireGuzzle();
if (!$this->guzzleIsInstalled()) {
throw new GuzzleRequiredException();
}
}
/**
* Determine whether Guzzle is installed
*
* @return bool
*/
protected function guzzleIsInstalled(): bool
{
return class_exists(Client::class);
}
/**
* Retrieve the JSON response of the given URL
*