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

Adding Static Code Analysis using phpstan #25

Open
pamtbaau opened this issue Mar 20, 2023 · 2 comments
Open

Adding Static Code Analysis using phpstan #25

pamtbaau opened this issue Mar 20, 2023 · 2 comments
Assignees

Comments

@pamtbaau
Copy link
Collaborator

Analysing code using a static code analyser like phpstan of psalm reduces the changes on bugs.

Here is a step-by-step manual to add phpstan.

In the root of the website used for developing pushy, do the following:

  • Run $ composer update
    This will install the development dependencies used by Grav
  • Run code analysis
    $ vendor/bin/phpstan analyse -l 6 ./user/plugins/pushy/pushy.php ./user/plugins/pushy/classes
    Arg -l denotes the strictness of the analysis. The higher the more strict. Level 6 might be a bit overwhelming on first use.

See the docs of phpstan for more information.

@hughbris hughbris self-assigned this Mar 21, 2023
@hughbris
Copy link
Owner

Nice. I installed and ran this and will run again after applying your latest changes, making any fixes suggested. I'll look into integrating this with a pre-commit hook, too. Thank for this!

Not sure when you consider this closeable, I'll let you decide :)

@pamtbaau
Copy link
Collaborator Author

Forgot to add one thing... You'll need to add config file phpstan.neon to the root of the site and add the following content:

parameters:
    scanDirectories:
      - user/plugins/pushy/vendor/czproject/git-php/src

This will tell phpstan where the git library can be found. That will reduce the number of errors listed by phpstan on calls to library methods...

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

No branches or pull requests

2 participants