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

discussion: PHPStan 11 array rules #8011

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

keradus
Copy link
Member

@keradus keradus commented May 15, 2024

shall we enable?
(eg enable with exception counter).
it's like ~900 violations in current codebase.

@keradus
Copy link
Member Author

keradus commented May 15, 2024

@localheinz @julienfalque @kubawerlos @SpacePossum @Wirone
would like to hear your voice, if you have opinion on that

@coveralls
Copy link

coveralls commented May 15, 2024

Coverage Status

coverage: 96.118%. remained the same
when pulling 0717c0c on keradus:phpstan11_
into 8d5cccf on PHP-CS-Fixer:master.

@localheinz localheinz self-requested a review May 15, 2024 09:01
@mvorisek
Copy link
Contributor

I do not think this is good idea until phpstan/phpstan#8438 is implemented.

@Wirone
Copy link
Member

Wirone commented May 15, 2024

@keradus what would be the real added value when we enable this? I believe we currently enforce proper array shapes for new code, and have already errors dump in the baseline. Enabling this option would probably make it even stricter, but I would rather prefer resolving root problems like fixers' config shapes, then would go into stricter analysis. Can you provide examples of what currently is not reported by tests/SA, which would be reported when these options are enabled?

@keradus
Copy link
Member Author

keradus commented May 15, 2024

@Wirone overall you recommended that rule to me somewhere so I was not looking into it deeply.
I want to avoid having random array<mix, mix> implicitly, and I do not like function (foo): int { return $arr[$foo] } when it can return null

reportPossiblyNonexistentGeneralArrayOffset

 ------ ------------------------------------------------------------------- 
  Line   src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php                 
 ------ ------------------------------------------------------------------- 
  69     Offset 1 might not exist on array<string>.  
 ------ ------------------------------------------------------------------- 


 ------ -------------------------------------------------------- 
  Line   src/Fixer/Casing/MagicConstantCasingFixer.php           
 ------ -------------------------------------------------------- 
  50     Offset int|null might not exist on array<int, string>.  
 ------ -------------------------------------------------------- 
  

reportPossiblyNonexistentConstantArrayOffset

 ------ ------------------------------------------------------------------------------------------------ 
  Line   src/Fixer/PhpUnit/PhpUnitExpectationFixer.php                                                   
 ------ ------------------------------------------------------------------------------------------------ 
  222    Offset int<1, max> might not exist on array{'expectException', string, 'expectExceptionCode'}.  
 ------ ------------------------------------------------------------------------------------------------ 

so it finds some interesting concerns

I like the argument of I would rather prefer resolving root problems like fixers' config shapes, then would go into stricter analysis
The rules are reporting that issue and we can go with regular path, of acknowledging the baseline yet prevent any new issue like that to appear again

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.

None yet

5 participants