cache icon indicating copy to clipboard operation
cache copied to clipboard

fix: setMultiple and deleteMultiple must only return boolean

Open phil-davis opened this issue 2 years ago • 1 comments

$ composer phpstan
> phpstan analyse lib tests
Note: Using configuration file /home/phil/git/sabre-io/cache/phpstan.neon.
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  Line   lib/Apcu.php                                                                                                                                                            
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  145    Return type (array|bool) of method Sabre\Cache\Apcu::setMultiple() should be covariant with return type (bool) of method Psr\SimpleCache\CacheInterface::setMultiple()  
  175    Return type (array|bool) of method Sabre\Cache\Apcu::deleteMultiple() should be covariant with return type (bool) of method                                             
         Psr\SimpleCache\CacheInterface::deleteMultiple()                                                                                                                        
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 


                                                                                                                        
 [ERROR] Found 2 errors                                                                                                 
                                                                                                                        

Script phpstan analyse lib tests handling the phpstan event returned with error code 1

with phpstan level 3 it correctly detects that setMultiple and deleteMultiple must only return boolean.

https://github.com/php-fig/simple-cache/pull/24 explicitly added the boolean return type to these methods, released in major version 3. That was released for PHP 8.

But we currently support PHP 7.4 also. That causes psr/simple-cache major version 1 to still be used. That declares the return type only in PHPdoc (which phpstan is finding).

Probably the current code works fine if someone is checking for an array in the return value, and processing it to find out what went wrong (if anything). So the change in this PR would break that. PHP 7.4 is not going to fall over at run-time just because setMultiple or deleteMultiple returns something not declared in the PHP doc.

So I will leave this here for now - probably better to sort this out with a major version some day, along with dropping PHP 7.4 support and bringing in psr/simple-cache v2 and then v3.

Also should have unit tests that check the return value.

phil-davis avatar Dec 04 '23 08:12 phil-davis

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (be1f12e) 98.75% compared to head (a6a2ef8) 97.59%. Report is 1 commits behind head on master.

Files Patch % Lines
lib/Apcu.php 77.77% 2 Missing :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #62      +/-   ##
============================================
- Coverage     98.75%   97.59%   -1.16%     
- Complexity       89       91       +2     
============================================
  Files             4        4              
  Lines           160      166       +6     
============================================
+ Hits            158      162       +4     
- Misses            2        4       +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Dec 04 '23 08:12 codecov[bot]