I am splitting off a side issue from
#2908886: Split off schema management out of schema.inc
From a new service method SchemaVersionHandler::setInstalledVersion() I want to enforce a return type of void.
public function setInstalledVersion(string $module, string $version): void {
$this->keyValue->get('system.schema')->set($module, $version);
$this->currentVersions[$module] = $version;
}
this is not possible with the current Builder, the output ALWAYS returns what it is was given
public function setInstalledVersion(string $module, string $version): void
{
return $this->lazyLoadItself()->setInstalledVersion($module, $version);
}
I am going to modify builder to just call the method without explicit return
PS
Just for context the proxyBuilder was recently semi-forced to start accounting for type to avoid conflicts with Symfony 5
https://www.drupal.org/project/drupal/issues/3125234
Comments
Comment #2
martin107 commentedThe fix is simple.
The existing test strategy was comprehensive .. making is a dream to add to the tests. :)
Comment #3
martin107 commentedComment #4
martin107 commentedResolved CS issues.
Comment #5
andypostComment #6
andypostIt looks more like bug, please add test as fail.patch
Moreover it looks backportable to 8.9 because required php version supports it already
EDIT 7.1 https://wiki.php.net/rfc/void_return_type
Comment #7
martin107 commentedThank you for adding that perspective ... andypost++
In general, we have no control over what Symfony5 will hand us.
This really is a follow up to a bug I added ...[ hangs head in shame. ]
I will add a patch tonight.
Comment #8
martin107 commentedHere is the smallest patch which shows the failure.
I have added a new class -- AboutToFail.php
core/lib/Drupal/Core/File/MimeType/AboutToFail.php
I then ran the appropriate script to trigger the ProxyBuilder into generating the proxy class.
The result is
core/lib/Drupal/Core/ProxyClass/File/MimeType/AboutToFail.php
As can be seen the generated file contains a syntax error with message...
"A void function cannot return a value."
Comment #9
longwaveGood spot, thanks for fixing this! I agree this can't go back to 8.9 because void return type is not valid in PHP 7.0.
Extra blank line at start of method. Variable name should be $returns_void.
hasReturnType()could be used for the first part.Or we could just roll the variable into here? e.g.
Comment #10
martin107 commentedLongwave - thanks for coming back and reviewing part 2 of this little thing.
Fixed.
Comment #11
longwaveLooks good now, a simple fix and the test coverage is straightforward.
Comment #12
alexpottCommitted and pushed 4c29b0788c to 9.1.x and b425254cc7 to 9.0.x. Thanks!
Backported to 9.0.x to keep things consistent.