- 
                Notifications
    You must be signed in to change notification settings 
- Fork 455
Description
cc @bshaffer, as asked I move the discussion to an issue.
As already discusses in
- [Translate] Remove final from TranslationServiceClient #8492
- Remove final from client without interfaces gapic-generator-php#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 ([DISCUSSION] Doubling final classes inspection in PHPStorm dg/bypass-finals#62) and static analysis tool like PHPStan (PHPStan unresolvable type for intersection of final and MockObject phpstan/phpstan#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 !