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

Add base PHPStan configuration #21

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

Conversation

Steveb-p
Copy link
Contributor

@Steveb-p Steveb-p commented Jan 4, 2024

This PR adds PHPStan static analysis library + Github workflow to launch those tests automatically.

Selected ruleset level is 5, which is the recommended value for catching all basic PHP code issues. You can see the rulesets here: https://phpstan.org/user-guide/rule-levels.

  1. basic checks, unknown classes, unknown functions, unknown methods called on $this, wrong number of arguments passed to those methods and functions, always undefined variables
  2. possibly undefined variables, unknown magic methods and properties on classes with __call and __get
  3. unknown methods checked on all expressions (not just $this), validating PHPDocs
  4. return types, types assigned to properties
  5. basic dead code checking - always false instanceof and other type checks, dead else branches, unreachable code after return; etc.
  6. checking types of arguments passed to methods and functions
  7. report missing typehints
  8. report partially wrong union types - if you call a method that only exists on some types in a union type, level 7 starts to report that; other possibly incorrect situations
  9. report calling methods and accessing properties on nullable types
  10. be strict about the mixed type - the only allowed operation you can do with it is to pass it to another mixed

All existing issues are put into "baseline", except me changing the PHPDoc for the Api factory methods.

A higher ruleset is available as needed (and usually recommended level is 7-8).

See:

Supamiu
Supamiu previously approved these changes Jan 5, 2024
@Steveb-p
Copy link
Contributor Author

Steveb-p commented Jan 5, 2024

Give me a moment to do a proper rebase :)

@Supamiu
Copy link
Contributor

Supamiu commented Jan 5, 2024

Sure, thanks a lot for your contributions by the way ! 😄

@Steveb-p
Copy link
Contributor Author

Steveb-p commented Jan 5, 2024

Sure, thanks a lot for your contributions by the way ! 😄

Well, I do intend to make use of the library (initially used xivapi API, but got errors and tried to pinpoint the issue - seems like an old version is still running on xivapi.com).

Now that I've seen the parser I'll probably rely on it instead. Going to put it into a Symfony 6 or 7 project (so also PHP8) and looking if it will work, and how much is needed to keep it updated.

So yeah, I should be thanking you instead 😅

(Rebase is done and finished).

@Steveb-p
Copy link
Contributor Author

Steveb-p commented Feb 6, 2024

@Supamiu everything is ready, if the PR is ok :)

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.

2 participants