Consider removing final from client classes
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start by reading the discussion in this issue and the referenced google-cloud-php pull request 8492 and gapic-generator-php pull request 774. Compare the proposed PHPDoc @final and interface approaches, then confirm the maintainers' decision and the client-library scope before defining what completion means.
Written by the indexing model from the issue text.
Description
cc @bshaffer, as asked I move the discussion to an issue.
As already discusses in
- https://github.com/googleapis/google-cloud-php/pull/8492
- https://github.com/googleapis/gapic-generator-php/pull/774
The current fact that client like TranslationServiceClient are final have the current drawback of
- not being able to be extended
- therefor not being able to be mocked for tests
While I do understand that google does not want such service to be extended (and I don't see a real need personally), on the contrary it's annoying to me to not being able to mock such external-client service in tests.
The current proposed solution is to use https://github.com/dg/bypass-finals in order to remove the final keyword at runtime.
I encounter the following (at least two) issue with this bypass library:
- First, if google use final but promote using this lib to remove the keyword, it doesn't forbid anyone to extend the final classes and therefor it's useless to add a final keyword at the first place
- Secondly and most annoying, both PHPStorm (https://github.com/dg/bypass-finals/issues/62) and static analysis tool like PHPStan (https://github.com/phpstan/phpstan/issues/8901) are not understanding bypass-final and report errors.
The two possible solutions I have in mind would be:
- Removing
finalhard keyword and use the soft one with phpdoc@final. - Or introducing an interface for each existing client, listing every public method of the client.
While the second one seems to be the right one, I understand google might not want to introduce 100 new interfaces with tons of methods and prefer the first one as a quickwin.
Quoting:
I don't want to be stubborn on this, however. If there's more support from our developers that bypass-finals is not sufficient, and using final is too much of a pain, I'm happy to remove it from the client libraries!
So if you encounter any issue with those final classes, please share a word !
- Dominant language
- PHP
- Stars
- 1.2k
- Forks
- 464
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 103
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from googleapis/google-cloud-php
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
googleapis/google-cloud-php#9730 ·
-
type: feature request
Difficulty 1/5 Under an hour Newbie friendliness 75/100
googleapis/google-cloud-php#9716 · 11 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
googleapis/google-cloud-php#9725 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
googleapis/google-cloud-php#9675 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
googleapis/google-cloud-php#9674 · 1 comment ·
All issues in googleapis/google-cloud-php
Similar issues
-
tooling
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
UX
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ProfessionalWiki/NeoWiki#1525 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
OpenConext/OpenConext-engineblock#2122 ·
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Automattic/safe-publish#594 ·