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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Php CodeSniffer and PHPStan Fix #84 #143

Merged
merged 4 commits into from Oct 19, 2023

Conversation

BrianHenryIE
Copy link
Contributor

@BrianHenryIE BrianHenryIE commented Aug 20, 2023

Run composer lint to run manually.
Automatically runs locally on commits.
Automatically runs on GitHub on pushes.

Adds:

  • PSR-12 Php CodeSniffer ruleset
  • PHPStan level 6 rule
  • Git hooks to auto-run phpcbf (Code Beautifer) on commits
  • GitHub Actions to auto-run phpcbf on pushes to master and to validate PhpStan
  • README badges to indicate code style and PhpStan level PHPCS PSR-12 PHPStan

When this is merged, it will automatically run on the existing code. Pending PRs will probably have to rebase to master before merging.

Most other CodeSniffer rulesets are based on PSR-12, so this is just a baseline to get started. PHPStan levels go up to 9, so 6 is a moderate compromise to aim for for now.

phpcs:

FILE: /Users/brianhenry/Sites/monerophp/src/mnemonic.php
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 19 ERRORS AND 2 WARNINGS AFFECTING 17 LINES
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   1 | WARNING | A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but
     |         | should not do both. The first symbol is defined on line 37 and the first side effect is on line 302.
  37 | ERROR   | Class name "mnemonic" is not in PascalCase format
  42 | ERROR   | Visibility must be declared on method "checksum"
  61 | ERROR   | Method name "mnemonic::validate_checksum" is not in camel caps format
 159 | WARNING | Line exceeds 120 characters; contains 173 characters
 277 | ERROR   | Each class must be in a file by itself
 302 | ERROR   | Closing brace must not be followed by any comment or statement on the same line
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

phpstan analyse:

------ -------------------------------------------------------------------------------------------------------------------------- 
  Line   mnemonic.php                                                                                                              
 ------ -------------------------------------------------------------------------------------------------------------------------- 
  42     Method MoneroIntegrations\MoneroPhp\mnemonic::checksum() has no return type specified.                                    
  42     Method MoneroIntegrations\MoneroPhp\mnemonic::checksum() has parameter $prefix_len with no type specified.                
  45     Parameter #2 $offset of function array_slice expects int, null given.                                                     
  72     Parameter #3 $pad_string of function str_pad expects string, int given.                                                   
  301    Method MoneroIntegrations\MoneroPhp\wordset::words() return type has no value type specified in iterable type array.      
         馃挕 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type                                  
 ------ -------------------------------------------------------------------------------------------------------------------------- 

Fixes #84

@BrianHenryIE BrianHenryIE changed the title Add Php CodeSniffer and PHPStan #84 Add Php CodeSniffer and PHPStan Fix #84 Aug 20, 2023
Copy link
Contributor

@recanman recanman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, ready to merge.

@recanman recanman mentioned this pull request Sep 29, 2023
@serhack serhack merged commit eda8248 into monero-integrations:master Oct 19, 2023
@serhack
Copy link
Member

serhack commented Oct 19, 2023

Thanks a lot!

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.

Use code stype
3 participants