monero-integrations / monerophp

Monero PHP library + JsonRPC Client
MIT License
119 stars 76 forks source link

Add Php CodeSniffer and PHPStan Fix #84 #143

Closed BrianHenryIE closed 1 year ago

BrianHenryIE commented 1 year ago

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

Adds:

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

serhack commented 1 year ago

Thanks a lot!