4343use DomainException ;
4444use InvalidArgumentException ;
4545use LogicException ;
46+ use UnexpectedValueException ;
4647
4748/**
4849 * The Google API Client
@@ -58,7 +59,7 @@ class Client
5859 const API_BASE_PATH = 'https://www.googleapis.com ' ;
5960
6061 /**
61- * @var OAuth2 $auth
62+ * @var ? OAuth2 $auth
6263 */
6364 private $ auth ;
6465
@@ -68,7 +69,7 @@ class Client
6869 private $ http ;
6970
7071 /**
71- * @var CacheItemPoolInterface $cache
72+ * @var ? CacheItemPoolInterface $cache
7273 */
7374 private $ cache ;
7475
@@ -83,12 +84,12 @@ class Client
8384 private $ config ;
8485
8586 /**
86- * @var LoggerInterface $logger
87+ * @var ? LoggerInterface $logger
8788 */
8889 private $ logger ;
8990
9091 /**
91- * @var CredentialsLoader $credentials
92+ * @var ? CredentialsLoader $credentials
9293 */
9394 private $ credentials ;
9495
@@ -225,7 +226,7 @@ public function getLibraryVersion()
225226 * For backwards compatibility
226227 * alias for fetchAccessTokenWithAuthCode
227228 *
228- * @param $code string code from accounts.google.com
229+ * @param string $code string code from accounts.google.com
229230 * @return array access token
230231 * @deprecated
231232 */
@@ -238,7 +239,7 @@ public function authenticate($code)
238239 * Attempt to exchange a code for an valid authentication token.
239240 * Helper wrapped around the OAuth 2.0 implementation.
240241 *
241- * @param $code string code from accounts.google.com
242+ * @param string $code code from accounts.google.com
242243 * @return array access token
243244 */
244245 public function fetchAccessTokenWithAuthCode ($ code )
@@ -714,7 +715,7 @@ public function setDeveloperKey($developerKey)
714715 * Set the hd (hosted domain) parameter streamlines the login process for
715716 * Google Apps hosted accounts. By including the domain of the user, you
716717 * restrict sign-in to accounts at that domain.
717- * @param $hd string - the domain to use.
718+ * @param string $hd the domain to use.
718719 */
719720 public function setHostedDomain ($ hd )
720721 {
@@ -725,7 +726,7 @@ public function setHostedDomain($hd)
725726 * Set the prompt hint. Valid values are none, consent and select_account.
726727 * If no value is specified and the user has not previously authorized
727728 * access, then the user is shown a consent screen.
728- * @param $prompt string
729+ * @param string $prompt
729730 * {@code "none"} Do not display any authentication or consent screens. Must not be specified with other values.
730731 * {@code "consent"} Prompt the user for consent.
731732 * {@code "select_account"} Prompt the user to select an account.
@@ -739,7 +740,7 @@ public function setPrompt($prompt)
739740 * openid.realm is a parameter from the OpenID 2.0 protocol, not from OAuth
740741 * 2.0. It is used in OpenID 2.0 requests to signify the URL-space for which
741742 * an authentication request is valid.
742- * @param $realm string - the URL-space to use.
743+ * @param string $realm the URL-space to use.
743744 */
744745 public function setOpenidRealm ($ realm )
745746 {
@@ -750,7 +751,7 @@ public function setOpenidRealm($realm)
750751 * If this is provided with the value true, and the authorization request is
751752 * granted, the authorization will include any previous authorizations
752753 * granted to this user/application combination for other scopes.
753- * @param $include boolean - the URL-space to use.
754+ * @param bool $include the URL-space to use.
754755 */
755756 public function setIncludeGrantedScopes ($ include )
756757 {
@@ -834,7 +835,7 @@ public function setScopes($scope_or_scopes)
834835 * Will append any scopes not previously requested to the scope parameter.
835836 * A single string will be treated as a scope to request. An array of strings
836837 * will each be appended.
837- * @param $scope_or_scopes string|array e.g. "profile"
838+ * @param string|string[] $scope_or_scopes e.g. "profile"
838839 */
839840 public function addScope ($ scope_or_scopes )
840841 {
@@ -873,10 +874,11 @@ public function prepareScopes()
873874 /**
874875 * Helper method to execute deferred HTTP requests.
875876 *
876- * @param $request RequestInterface|\Google\Http\Batch
877- * @param string $expectedClass
877+ * @template T
878+ * @param RequestInterface $request
879+ * @param class-string<T> $expectedClass
878880 * @throws \Google\Exception
879- * @return mixed|$expectedClass |ResponseInterface
881+ * @return mixed|T |ResponseInterface
880882 */
881883 public function execute (RequestInterface $ request , $ expectedClass = null )
882884 {
@@ -902,7 +904,7 @@ public function execute(RequestInterface $request, $expectedClass = null)
902904 if ($ this ->config ['api_format_v2 ' ]) {
903905 $ request = $ request ->withHeader (
904906 'X-GOOG-API-FORMAT-VERSION ' ,
905- 2
907+ ' 2 '
906908 );
907909 }
908910
@@ -1182,6 +1184,7 @@ protected function createDefaultHttpClient()
11821184 if (defined ('\GuzzleHttp\ClientInterface::MAJOR_VERSION ' )) {
11831185 $ guzzleVersion = ClientInterface::MAJOR_VERSION ;
11841186 } elseif (defined ('\GuzzleHttp\ClientInterface::VERSION ' )) {
1187+ // @phpstan-ignore-next-line
11851188 $ guzzleVersion = (int )substr (ClientInterface::VERSION , 0 , 1 );
11861189 }
11871190
@@ -1191,9 +1194,11 @@ protected function createDefaultHttpClient()
11911194 'defaults ' => ['exceptions ' => false ],
11921195 ];
11931196 if ($ this ->isAppEngine ()) {
1194- // set StreamHandler on AppEngine by default
1195- $ options ['handler ' ] = new StreamHandler ();
1196- $ options ['defaults ' ]['verify ' ] = '/etc/ca-certificates.crt ' ;
1197+ if (class_exists (StreamHandler::class)) {
1198+ // set StreamHandler on AppEngine by default
1199+ $ options ['handler ' ] = new StreamHandler ();
1200+ $ options ['defaults ' ]['verify ' ] = '/etc/ca-certificates.crt ' ;
1201+ }
11971202 }
11981203 } elseif (6 === $ guzzleVersion || 7 === $ guzzleVersion ) {
11991204 // guzzle 6 or 7
0 commit comments