diff --git a/composer.json b/composer.json index 8fc208e..8c7b61e 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "php": "^7.1.3", "ext-json": "*", "psr/log": "^1.0", - "symfony/http-client": "^4.3", + "symfony/http-client": "^4.3" }, "require-dev": { "symfony/form": "^2.1|^3.0|^4.0", diff --git a/src/SymfonyCorp/Connect/Api/Api.php b/src/SymfonyCorp/Connect/Api/Api.php index 57f6132..d23741a 100644 --- a/src/SymfonyCorp/Connect/Api/Api.php +++ b/src/SymfonyCorp/Connect/Api/Api.php @@ -12,12 +12,12 @@ namespace SymfonyCorp\Connect\Api; use Buzz\Browser; +use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Symfony\Component\HttpClient\HttpClient; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; -use Psr\Log\LoggerInterface; -use Psr\Log\NullLogger; use Symfony\Contracts\HttpClient\ResponseInterface; use SymfonyCorp\Connect\Api\Parser\ParserInterface; use SymfonyCorp\Connect\Api\Parser\VndComSymfonyConnectXmlParser as Parser; @@ -40,13 +40,16 @@ class Api private $endpoint; private $accessToken; + /** + * @param HttpClientInterface|null $httpClient + */ public function __construct($endpoint = null, $httpClient = null, ParserInterface $parser = null, LoggerInterface $logger = null) { if ($httpClient instanceof Browser) { @trigger_error(sprintf('Passing a "%s" to "%s()" is deprecated since symfonycorp/connect 5.1, use "%s" instead.', Browser::class, __METHOD__, HttpClientInterface::class), E_USER_DEPRECATED); $httpClient = null; - } elseif ($httpClient && !$httpClient instanceof HttpClientInterface) { - throw new \InvalidArgumentException(sprintf('Argument 2 passed to %s() must be an instance of %s or null, %s given', __METHOD__, HttpClientInterface::class, is_object($httpClient) ? get_class($httpClient) : gettype($httpClient))); + } elseif (null !== $httpClient && !$httpClient instanceof HttpClientInterface) { + throw new \TypeError(sprintf('Argument 2 passed to %s() must be an instance of %s or null, %s given', __METHOD__, HttpClientInterface::class, \is_object($httpClient) ? \get_class($httpClient) : \gettype($httpClient))); } $this->httpClient = $httpClient ?: HttpClient::create(); diff --git a/src/SymfonyCorp/Connect/OAuthConsumer.php b/src/SymfonyCorp/Connect/OAuthConsumer.php index 48c636b..e8197d2 100644 --- a/src/SymfonyCorp/Connect/OAuthConsumer.php +++ b/src/SymfonyCorp/Connect/OAuthConsumer.php @@ -13,8 +13,8 @@ use Buzz\Browser; use Buzz\Client\Curl; -use Psr\Log\NullLogger; use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Symfony\Component\HttpClient\HttpClient; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -42,13 +42,16 @@ class OAuthConsumer 'authorize' => '/oauth/authorize', ]; + /** + * @param HttpClientInterface|null $httpClient + */ public function __construct($appId, $appSecret, $scope, $endpoint = null, $httpClient = null, LoggerInterface $logger = null) { if ($httpClient instanceof Browser) { @trigger_error(sprintf('Passing a "%s" to "%s()" is deprecated since symfonycorp/connect 5.1, use "%s" instead.', Browser::class, __METHOD__, HttpClientInterface::class), E_USER_DEPRECATED); $httpClient = null; - } elseif ($httpClient && !$httpClient instanceof HttpClientInterface) { - throw new \InvalidArgumentException(sprintf('Argument 5 passed to %s() must be an instance of %s or null, %s given', __METHOD__, HttpClientInterface::class, is_object($httpClient) ? get_class($httpClient) : gettype($httpClient))); + } elseif (null !== $httpClient && !$httpClient instanceof HttpClientInterface) { + throw new \TypeError(sprintf('Argument 5 passed to %s() must be an instance of %s or null, %s given', __METHOD__, HttpClientInterface::class, \is_object($httpClient) ? \get_class($httpClient) : \gettype($httpClient))); } $this->httpClient = $httpClient ?: HttpClient::create(); @@ -164,9 +167,12 @@ public function getEndpoint() return $this->endpoint; } + /** + * @deprecated since symfonycorp/connect 5.1 + */ public function getBrowser() { - @trigger_error(sprintf('"%s()" has been deprecated since symfonycorp/connect 5.1.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('"%s()" is deprecated since symfonycorp/connect 5.1.', __METHOD__), E_USER_DEPRECATED); if (!class_exists(Browser::class)) { throw new \LogicException(sprintf('You cannot use "%s()" as the "kriswallsmith/buzz" package is not installed, try running "composer require kriswallsmith/buzz".', Browser::class)); diff --git a/tests/SymfonyCorp/Connect/Tests/Api/ApiTest.php b/tests/SymfonyCorp/Connect/Tests/Api/ApiTest.php index 614a3cf..cf792b8 100644 --- a/tests/SymfonyCorp/Connect/Tests/Api/ApiTest.php +++ b/tests/SymfonyCorp/Connect/Tests/Api/ApiTest.php @@ -11,12 +11,12 @@ namespace SymfonyCorp\Connect\Test\Api; +use PHPUnit\Framework\TestCase; use Symfony\Component\HttpClient\MockHttpClient; use Symfony\Component\HttpClient\Response\MockResponse; use Symfony\Contracts\HttpClient\HttpClientInterface; use SymfonyCorp\Connect\Api\Api; use SymfonyCorp\Connect\Api\Entity\Root; -use PHPUnit\Framework\TestCase; /** * ApitTest.