-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cast contentId and locationId command arguments to integer #2582
Conversation
PHP Fatal error: Uncaught TypeError: Ibexa\Core\Repository\SiteAccessAware\LocationService::loadLocation(): Argument #1 ($locationId) must be of type int, string given, called in /var/www/html/src/Command/BrowseLocationsCommand.php on line 45 and defined in /var/www/html/vendor/ibexa/core/src/lib/Repository/SiteAccessAware/LocationService.php:53
@@ -40,7 +40,7 @@ private function browseLocation(Location $location, OutputInterface $output, int | |||
|
|||
protected function execute(InputInterface $input, OutputInterface $output): int | |||
{ | |||
$locationId = $input->getArgument('locationId'); | |||
$locationId = (int) $input->getArgument('locationId'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mnocon Why PHPStan didn't see an issue here?
https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/Console/Input/InputInterface.php#L83-L90 declares returning mixed
but in fact it's probably only int|array
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one would be detected using level 9:
https://phpstan.org/user-guide/rule-levels
Bumping it results in:
Line api/public_php_api/src/Command/BrowseLocationsCommand.php
------ ------------------------------------------------------------------------------------------------------------------------------
:45 Parameter #1 $locationId of method Ibexa\Contracts\Core\Repository\LocationService::loadLocation() expects int, mixed given.
------ ------------------------------------------------------------------------------------------------------------------------------
(and another 147 errors)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can think if we want to introduce this (level 10 is the highest right now), in product code we use level 8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mnocon I don't fix 147 errors here 😛. I would say that we don't need it in CI. I'm curious about those level 9 new errors. But there is already a hundred to check in the actual level 8 phpstan-baseline.neon 😅
code_samples/ change report
|
* BrowseLocationsCommand.php: Cast locationId arg to int PHP Fatal error: Uncaught TypeError: Ibexa\Core\Repository\SiteAccessAware\LocationService::loadLocation(): Argument #1 ($locationId) must be of type int, string given, called in /var/www/html/src/Command/BrowseLocationsCommand.php on line 45 and defined in /var/www/html/vendor/ibexa/core/src/lib/Repository/SiteAccessAware/LocationService.php:53 * code_samples/: cast location and content ID arguments to int (cherry picked from commit 8a760dd)
Fix
PHP Fatal error: Uncaught TypeError: Ibexa\Core\Repository\SiteAccessAware\LocationService::loadLocation(): Argument #1 ($locationId) must be of type int, string given, called in /var/www/html/src/Command/BrowseLocationsCommand.php on line 45 and defined in /var/www/html/vendor/ibexa/core/src/lib/Repository/SiteAccessAware/LocationService.php:53
I didn't test the others but casting every 'contentId' or 'locationId' to
int
is probably a good habit.Checklist