Problem/Motivation

At https://git.drupalcode.org/project/google_api_client/-/blob/8.x-3.x/src/... private function for

::getClient(Google_Client $client ) 

The $client argument is correctly typed to the Google_Client class but the caller allows $client to be a null (also PHPDocs say so). in PHP 7.3 (and probably 7.2 too and that is the reason maybe this has not exploded) that is not allowed and throws an invalid type exception when trying to authenticate a Client.

TypeError: Argument 1 passed to Drupal\google_api_client\Service\GoogleApiClientService::getClient() must be an instance of Google_Client, null given, called in

Steps to reproduce

Deploy the module (via composer) on Drupal 8.9.x under PHP 7.3. Create a Client Entity. try to Authenticate

You should see:

TypeError: Argument 1 passed to Drupal\google_api_client\Service\GoogleApiClientService::getClient() must be an instance of Google_Client, null given, called in

Proposed resolution

Quite simple
::getClient(Google_Client $client = null ) //give it a default, that way it is correctly type but also allows null.

Remaining tasks

Maintainer testing/reproduceability?

User interface changes

None

API changes

None

Data model changes

None

CommentFileSizeAuthor
#3 3172577-3.patch1.21 KBsadashiv
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

DiegoPino created an issue. See original summary.

bunty badgujar’s picture

Priority: Normal » Major
Related issues: +#3180902: Authenticate not working

I am also facing same issue on 3.0@RC with PHP 7.3. Not able to auth after adding account. Also, add similar issue in related tab.

sadashiv’s picture

Status: Active » Needs review
StatusFileSize
new1.21 KB

Thanks for reporting,

Can you try applying this patch?

Thanks,
Sadashiv.

diegopino’s picture

Thanks a lot. Will test ASAP and report back

diegopino’s picture

@sadashiv sorry to report but the fix is targeting the incorrect spot.

Your patch is targeting the PHP DOCS for

public function setGoogleApiClient(GoogleApiClientInterface $google_api_client, Google_Client $googleClient = NULL)

At:
https://git.drupalcode.org/project/google_api_client/-/blob/8.x-3.x/src/...
https://git.drupalcode.org/project/google_api_client/-/blob/8.x-3.x/src/...

which is already correct because it sets the argument at default NULL

The issue is both function call $this->getClient($googleClient); with $googleClient == NULL and that function signature. For consistency with the rest of your code should also default to NULL there.

The issue persists because the you can not call getClient with the passed NULL. I made a gitlab ISSUE fork and submitted a merge request
https://git.drupalcode.org/project/google_api_client/-/merge_requests/1 with the corrected files

Let me know if you also want the patch file here too or the new workflow is good enough. Thanks

  • sadashiv committed 5f6b5aa on 8.x-3.x authored by DiegoPino
    Resolve #3172577 "Optional argument for googleClient is enforced"
    
sadashiv’s picture

Have released this as 8.x-3.0-rc4.

Thanks,
Sadashiv.

sadashiv’s picture

Status: Needs review » Fixed

Marking this fixed.

diegopino’s picture

Thanks a lot @sadashiv!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.