chesslablab / php-chess

A chess library for PHP offering move validation, common formats, multiple variants, UCI engine support, explanation of chess positions, and image recognition.
https://chesslablab.github.io/php-chess/
MIT License
110 stars 52 forks source link

Fixed PSR-12 compliance issues in src\UciEngine #629

Closed TheMarvelFan closed 1 month ago

TheMarvelFan commented 1 month ago

Closes #588

Fixed issues in all files.

Commits to be merged: 1

programarivm commented 1 month ago

Thank you @TheMarvelFan for this contribution!

Let me point out the following for future PRs:

Example:

Closes #588

Also it seems as if Chess\UciEngine\Details\Limit needs some fine-tuning:

----------------------------------------------------------------------
FOUND 10 ERRORS AFFECTING 10 LINES
----------------------------------------------------------------------
  1 | ERROR | [x] End of line character is invalid; expected "\n" but
    |       |     found "\r\n"
 15 | ERROR | [x] Expected at least 1 space after "?"; 0 found
 23 | ERROR | [x] Expected at least 1 space after "?"; 0 found
 30 | ERROR | [x] Expected at least 1 space after "?"; 0 found
 37 | ERROR | [x] Expected at least 1 space after "?"; 0 found
 44 | ERROR | [x] Expected at least 1 space after "?"; 0 found
 51 | ERROR | [x] Expected at least 1 space after "?"; 0 found
 58 | ERROR | [x] Expected at least 1 space after "?"; 0 found
 65 | ERROR | [x] Expected at least 1 space after "?"; 0 found
 72 | ERROR | [x] Expected at least 1 space after "?"; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 10 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 27ms; Memory: 2Mb

Happy coding,

TheMarvelFan commented 1 month ago

@programarivm

I will keep the linking of PR to issue in mind in the future.

I hope the issue in Chess\UciEngine\Details\Limit is fixed now.

I am attaching a screenshot of my phpcs local output in the terminal:

image

Here is the output from online PHP codesniffer:

image

(The line endings error is probably a copy/paste issue, as this has been fixed in my file)

programarivm commented 1 month ago

Thanks for the update! Chess\UciEngine\Details\Limit has been fixed and is now PSR12 compliant.

Chess\UciEngine\Details\UciInfoLine would need some fixing since it is also included in the Chess\UciEngine namespace.

----------------------------------------------------------------------
FOUND 33 ERRORS AFFECTING 26 LINES
----------------------------------------------------------------------
   1 | ERROR | [x] End of line character is invalid; expected "\n"
     |       |     but found "\r\n"
  19 | ERROR | [x] Expected at least 1 space after "?"; 0 found
  26 | ERROR | [x] Expected at least 1 space after "?"; 0 found
  33 | ERROR | [x] Expected at least 1 space after "?"; 0 found
  40 | ERROR | [x] Expected at least 1 space after "?"; 0 found
  47 | ERROR | [x] Expected at least 1 space after "?"; 0 found
  54 | ERROR | [x] Expected at least 1 space after "?"; 0 found
  61 | ERROR | [x] Expected at least 1 space after "?"; 0 found
  68 | ERROR | [x] Expected at least 1 space after "?"; 0 found
  75 | ERROR | [x] Expected at least 1 space after "?"; 0 found
  82 | ERROR | [x] Expected at least 1 space after "?"; 0 found
  89 | ERROR | [x] Expected at least 1 space before ":"; 0 found
 101 | ERROR | [x] Expected at least 1 space before ":"; 0 found
 124 | ERROR | [x] Expected at least 1 space before ":"; 0 found
 131 | ERROR | [ ] CASE statements must be defined using a colon
 131 | ERROR | [x] Expected at least 1 space before ":"; 0 found
 134 | ERROR | [ ] CASE statements must be defined using a colon
 134 | ERROR | [x] Expected at least 1 space before ":"; 0 found
 137 | ERROR | [ ] CASE statements must be defined using a colon
 137 | ERROR | [x] Expected at least 1 space before ":"; 0 found
 140 | ERROR | [ ] CASE statements must be defined using a colon
 140 | ERROR | [x] Expected at least 1 space before ":"; 0 found
 142 | ERROR | [x] Line indented incorrectly; expected 16 spaces,
     |       |     found 20
 145 | ERROR | [x] Line indented incorrectly; expected 16 spaces,
     |       |     found 20
 148 | ERROR | [ ] CASE statements must be defined using a colon
 148 | ERROR | [x] Expected at least 1 space before ":"; 0 found
 151 | ERROR | [ ] CASE statements must be defined using a colon
 151 | ERROR | [x] Expected at least 1 space before ":"; 0 found
 154 | ERROR | [ ] CASE statements must be defined using a colon
 154 | ERROR | [x] Expected at least 1 space before ":"; 0 found
 196 | ERROR | [x] Space before opening parenthesis of function call
     |       |     prohibited
 197 | ERROR | [x] Space before opening parenthesis of function call
     |       |     prohibited
 198 | ERROR | [x] Space before opening parenthesis of function call
     |       |     prohibited
----------------------------------------------------------------------
PHPCBF CAN FIX THE 26 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 53ms; Memory: 4Mb
TheMarvelFan commented 1 month ago

Hi @programarivm ,

I seem to be facing some kind of issue here.

image

I am not sure what the cause of this is. All the cases are having colons.

Besdies this, the web code sniffer seems to have a problem with the indentation of the if statement in lines 142 and 145. The code formatting that it approves is clearly wrong.

On the other hand, I locally use phpcs and phpcbf to detect and fix the compliance violations, and it seems like the phpcs PSR-12 standard has a disagreement with the PHP web code sniffer PSR-12 standard.

Screenshot 2024-10-14 215711 image

programarivm commented 1 month ago

Thank you @TheMarvelFan for the feedback!

It seems as if src/UciEngine/Details/Limit.php doesn't require any fixing.

In nullable type declarations, there MUST NOT be a space between the question mark and the type.

There may be something wrong with WebCodeSniffer.

See [4.5 Method and Function Arguments]()https://www.php-fig.org/psr/psr-12/#45-method-and-function-arguments.

TheMarvelFan commented 1 month ago

Alright then I will revert the file to its previous formatting.