Skip to content

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

@phil-davis

Description

@phil-davis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions