Skip to content
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

Quoting an int does not make phpstan know that it is now a string - 1.9.5 #8635

Closed
phil-davis opened this issue Jan 3, 2023 · 5 comments
Closed

Comments

@phil-davis
Copy link

phil-davis commented Jan 3, 2023

Bug report

Code snippet that reproduces the problem

		$data = $this->tokenService->GenerateNewAuthUserAccessToken("$fileId", $folderUrl, $user);

Expected output

Passes - GenerateNewAuthUserAccessToken expects a string in parameter1

Actual output

composer bin phpstan install --no-progress
[bamarni-bin] Checking namespace vendor-bin/phpstan
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking phpstan/phpstan (1.9.5)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing phpstan/phpstan (1.9.5): Extracting archive
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
php -d zend.enable_gc=0 vendor-bin/phpstan/vendor/bin/phpstan analyse --memory-limit=4G --configuration=./phpstan.neon --no-progress --level=5 appinfo lib

 ------ --------------------------------------------------------------------------------------------------------------------------- 
  Line   lib/Commands/GetToken.php                                                                                                  
 ------ --------------------------------------------------------------------------------------------------------------------------- 
  91     Parameter #1 $fileId of method OCA\WOPI\Service\TokenService::GenerateNewAuthUserAccessToken() expects string, int given.  
 ------ --------------------------------------------------------------------------------------------------------------------------- 
                                                                                                                        
 [ERROR] Found 1 error                                                                                                  
                                                                                                                        

With phpstan 1.9.4 this sort of code passes. The idiom "$intVariable" was analyzed OK. $intVariable is an int type, and the result of quoting it makes it into a string type, and satisfies a function call that requires a string parameter.

But with phpstan 1.9.5 it still thinks that the quoted string is an int, and complains about it.

a) Original code:

		$data = $this->tokenService->GenerateNewAuthUserAccessToken("$fileId", $folderUrl, $user);

b) If I do this, it still thinks that I am passing an int:

		$stringFileId = "$fileId";
		$data = $this->tokenService->GenerateNewAuthUserAccessToken($stringFileId, $folderUrl, $user);

c) If I explicitly cast to string, then it is happy:

		$data = $this->tokenService->GenerateNewAuthUserAccessToken((string) $fileId, $folderUrl, $user);

Making the code-change at (c) is fine. I am just raising this issue so that there is awareness that the phpstan behavior changed. Feel free to close if you think that the new behavior is correct/acceptable.

@mergeable
Copy link

mergeable bot commented Jan 3, 2023

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

I really need the reproduction on phpstan.org/try, thanks.

@phil-davis
Copy link
Author

I really need the reproduction on phpstan.org/try, thanks.

https://phpstan.org/r/04e0dea7-d8d9-4bbb-aec4-18cc3cf5fde7

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@dc77608

@github-actions
Copy link

github-actions bot commented Feb 4, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants