Skip to content

Conversation

@mfn
Copy link
Contributor

@mfn mfn commented Nov 28, 2021

Summary

Here's my proposal to add https://phpstan.org/user-guide/getting-started into this project 👋🏼

I've been using if for years in various projects to great success. It can be daunting at first for existing projects, but the sooner it's added, the better.

This PR includes:

  • making phpstan a dev dependency, add a basic config+baseline
    (it already was a transient one, this now makes it explicit)
  • add composer script entries for it
  • add a github action to run phpstan
    (which uses above composer script entries)
  • Add #[\ReturnTypeWillChange] annotation for PHP 8.1 compatibility
    This one was already exposed by phpstan 😅 and since annotations are comments and thus backwards compatible, this is the only "source level" change here:
     ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
      Line   src/Payload.php                                                                                                                                                         
     ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
      205    Return type mixed of method PHPOpenSourceSaver\JWTAuth\Payload::offsetExists() is not covariant with tentative return type bool of method ArrayAccess::offsetExists().  
             💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.                                                                  
      230    Return type mixed of method PHPOpenSourceSaver\JWTAuth\Payload::offsetSet() is not covariant with tentative return type void of method ArrayAccess::offsetSet().        
             💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.                                                                  
      244    Return type mixed of method PHPOpenSourceSaver\JWTAuth\Payload::offsetUnset() is not covariant with tentative return type void of method ArrayAccess::offsetUnset().    
             💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.                                                                  
      254    Return type mixed of method PHPOpenSourceSaver\JWTAuth\Payload::count() is not covariant with tentative return type int of method Countable::count().                   
             💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.                                                                  
     ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
    

Notes

  • I opted to run phpstan with PHP 8.1. This is important as the version you use to run phpstan is relevant and makes a difference in things being reported. I understand PHP 8.1 just left the door, but didn't see a reason to go lower.

    Personally, I do use OSX / homebrew and 8.1 is already available here, so for me local testing is possible already.

  • This PR is "as unobtrusive as possible" to get the foot in the door for phpstan. That's why I chose a) the lowest level and b) added it fully to the baseline without any fixes yet.
    I believe any fixes further on need to go into 2.x for the compatibility to transition from the forked package

Links

mfn added 5 commits November 28, 2021 22:34
Fixes phpstan:
```
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   src/Payload.php
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  205    Return type mixed of method PHPOpenSourceSaver\JWTAuth\Payload::offsetExists() is not covariant with tentative return type bool of method ArrayAccess::offsetExists().
         💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.
  230    Return type mixed of method PHPOpenSourceSaver\JWTAuth\Payload::offsetSet() is not covariant with tentative return type void of method ArrayAccess::offsetSet().
         💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.
  244    Return type mixed of method PHPOpenSourceSaver\JWTAuth\Payload::offsetUnset() is not covariant with tentative return type void of method ArrayAccess::offsetUnset().
         💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.
  254    Return type mixed of method PHPOpenSourceSaver\JWTAuth\Payload::count() is not covariant with tentative return type int of method Countable::count().
         💡 Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
```
@leon0399 leon0399 self-requested a review November 29, 2021 08:19
@mfn
Copy link
Contributor Author

mfn commented Nov 29, 2021

Okay 😅 I've added the branches to push!

@mfn mfn requested a review from leon0399 November 29, 2021 15:54
@Messhias
Copy link
Collaborator

Okay 😅 I've added the branches to push!

Nice, let's wait for @leon0399 updates.

@leon0399 leon0399 merged commit 24c96a9 into PHP-Open-Source-Saver:develop Nov 29, 2021
@mfn mfn deleted the mfn-phpstan branch November 29, 2021 20:15
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.

3 participants