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

fix: setMultiple and deleteMultiple must only return boolean #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

phil-davis
Copy link
Contributor

@phil-davis phil-davis commented Dec 4, 2023

$ 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.

php-fig/simple-cache#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.

Copy link

codecov bot commented Dec 4, 2023

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 ⚠️
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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant