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
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3172577-3.patch | 1.21 KB | sadashiv |
Issue fork google_api_client-3172577
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
Comment #2
bunty badgujar commentedI 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.
Comment #3
sadashiv commentedThanks for reporting,
Can you try applying this patch?
Thanks,
Sadashiv.
Comment #4
diegopino commentedThanks a lot. Will test ASAP and report back
Comment #6
diegopino commented@sadashiv sorry to report but the fix is targeting the incorrect spot.
Your patch is targeting the PHP DOCS for
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
Comment #8
sadashiv commentedHave released this as 8.x-3.0-rc4.
Thanks,
Sadashiv.
Comment #9
sadashiv commentedMarking this fixed.
Comment #10
diegopino commentedThanks a lot @sadashiv!