Skip to content

Cast contentId and locationId command arguments to integer #2582

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);

$parentLocationId = $input->getArgument('parentLocationId');
$contentId = $input->getArgument('contentId');
$parentLocationId = (int) $input->getArgument('parentLocationId');
$contentId = (int) $input->getArgument('contentId');

$locationCreateStruct = $this->locationService->newLocationCreateStruct($parentLocationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$locationId = $input->getArgument('locationId');
$locationId = (int) $input->getArgument('locationId');
$location = $this->locationService->loadLocation($locationId);

$this->bookmarkService->createBookmark($location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor Author

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.

Copy link
Contributor

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)

Copy link
Contributor

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

Copy link
Contributor Author

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 😅


$location = $this->locationService->loadLocation($locationId);
$this->browseLocation($location, $output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);

$parentLocationId = $input->getArgument('parentLocationId');
$parentLocationId = (int) $input->getArgument('parentLocationId');
$contentTypeIdentifier = $input->getArgument('contentType');
$name = $input->getArgument('name');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);

$locationId = $input->getArgument('locationId');
$locationId = (int) $input->getArgument('locationId');

$location = $this->locationService->loadLocation($locationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output)
{
$locationId = $input->getArgument('locationId');
$locationId = (int) $input->getArgument('locationId');
$contentTypeIdentifier = $input->getArgument('contentTypeIdentifier');
$text = $input->getArgument('text');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$contentTypeId = $input->getArgument('contentTypeId');
$contentTypeId = (int) $input->getArgument('contentTypeId');

$query = new Query();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);

$locationId = $input->getArgument('location_id');
$locationId = (int) $input->getArgument('location_id');

$location = $this->locationService->loadLocation($locationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);

$locationId = $input->getArgument('locationId');
$targetLocationId = $input->getArgument('targetLocationId');
$locationId = (int) $input->getArgument('locationId');
$targetLocationId = (int) $input->getArgument('targetLocationId');

$sourceLocation = $this->locationService->loadLocation($locationId);
$targetLocation = $this->locationService->loadLocation($targetLocationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if ($input->getArgument('contentID')) {
$contentId = $input->getArgument('contentID');
$contentId = (int) $input->getArgument('contentID');
$objectStateToAssign = $objectStateIdentifierList[0];
$contentInfo = $this->contentService->loadContentInfo($contentId);
$objectStateGroup = $this->objectStateService->loadObjectStateGroupByIdentifier($objectStateGroupIdentifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$sectionName = $input->getArgument('sectionName');
$sectionIdentifier = $input->getArgument('sectionIdentifier');
$contentId = $input->getArgument('contentId');
$contentId = (int) $input->getArgument('contentId');

$sectionCreateStruct = $this->sectionService->newSectionCreateStruct();
$sectionCreateStruct->name = $sectionName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);

$contentId = $input->getArgument('contentId');
$locationId = $input->getArgument('locationId');
$contentId = (int) $input->getArgument('contentId');
$locationId = (int) $input->getArgument('locationId');

$contentInfo = $this->contentService->loadContentInfo($contentId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);

$contentId = $input->getArgument('contentId');
$contentId = (int) $input->getArgument('contentId');
$language = $input->getArgument('language');
$newName = $input->getArgument('nameInNewLanguage');
$secondaryLanguage = $input->getArgument('secondaryLanguage');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);

$locationId = $input->getArgument('locationId');
$locationId = (int) $input->getArgument('locationId');
if ($input->getArgument('newParentId')) {
$newParentId = $input->getArgument('newParentId');
$newParentId = (int) $input->getArgument('newParentId');
}

$location = $this->locationService->loadLocation($locationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);

$contentId = $input->getArgument('contentId');
$contentId = (int) $input->getArgument('contentId');
$newName = $input->getArgument('newName');

$contentInfo = $this->contentService->loadContentInfo($contentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$contentId = $input->getArgument('contentId');
$contentId = (int) $input->getArgument('contentId');

$content = $this->contentService->loadContent($contentId);
$contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$contentId = $input->getArgument('contentId');
$contentId = (int) $input->getArgument('contentId');
$workflowName = $input->getArgument('workflowName');
$transitionName = $input->getArgument('transitionName');

Expand Down
Loading