Automattic / hidden-posts

The opposite of sticky posts.
GNU General Public License v2.0
11 stars 5 forks source link

Refactor plugin based on WordPress Coding Standards for PHP_CodeSniffer #15

Closed nielslange closed 3 years ago

nielslange commented 3 years ago

Running phpcs . --standard=WordPress --ignore="/vendor/*,/node_modules/*,/packages/*" --extensions=php -p currently results to:

E 1 / 1 (100%)

FILE: /Users/nielslange/wpvip/plugins/hidden-posts/hidden-posts.php
------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 114 ERRORS AND 6 WARNINGS AFFECTING 85 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------
   1 | ERROR   | [ ] Class file names should be based on the class name with "class-" prepended. Expected class-hidden-posts.php, but found
     |         |     hidden-posts.php.
   9 | ERROR   | [ ] Missing @package tag in file comment
  23 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  23 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
  24 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  26 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  27 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  28 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  29 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  31 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  31 | ERROR   | [ ] Missing doc comment for function __construct()
  31 | ERROR   | [ ] Visibility must be declared on method "__construct"
  32 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  33 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  34 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  35 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  37 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  37 | ERROR   | [ ] Doc comment for parameter "$query" missing
  38 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  39 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  40 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  40 | ERROR   | [ ] Visibility must be declared on method "pre_get_posts"
  41 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  41 | ERROR   | [x] Inline control structures are not allowed
  42 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  44 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  44 | ERROR   | [x] Inline control structures are not allowed
  45 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  48 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
  55 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  57 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  58 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  59 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  60 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  60 | ERROR   | [ ] Visibility must be declared on method "hidden_checkbox"
  61 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  63 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  63 | WARNING | [ ] Not using strict comparison for in_array; supply true for third argument.
  65 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  66 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  66 | ERROR   | [ ] All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found
     |         |     'self'.
  67 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  69 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  69 | ERROR   | [ ] Doc comment for parameter "$post" missing
  70 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  71 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  72 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  72 | ERROR   | [ ] Visibility must be declared on method "save_meta"
  73 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  73 | ERROR   | [ ] Inline comments must end in full-stops, exclamation marks, or question marks
  74 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  74 | ERROR   | [x] Inline control structures are not allowed
  74 | ERROR   | [ ] $_POST data not unslashed before sanitization. Use wp_unslash() or similar
  74 | ERROR   | [ ] Detected usage of a non-sanitized input variable: $_POST[self::NONCE_KEY]
  75 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  77 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  77 | ERROR   | [ ] Inline comments must end in full-stops, exclamation marks, or question marks
  78 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  78 | ERROR   | [x] Inline control structures are not allowed
  79 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  80 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  80 | ERROR   | [x] Expected 1 space(s) after ELSE keyword; newline found
  80 | ERROR   | [x] Inline control structures are not allowed
  81 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  82 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  84 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  85 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  86 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  87 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  87 | ERROR   | [ ] Visibility must be declared on method "get_posts"
  88 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  89 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  91 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  91 | ERROR   | [ ] Doc comment for parameter "$id" missing
  92 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  93 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  94 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  95 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  96 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  97 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  98 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
  98 | ERROR   | [ ] Visibility must be declared on method "add_post"
  99 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 101 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 101 | ERROR   | [x] Inline control structures are not allowed
 101 | WARNING | [ ] Not using strict comparison for in_array; supply true for third argument.
 102 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 104 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 104 | ERROR   | [ ] Inline comments must end in full-stops, exclamation marks, or question marks
 105 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 107 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 107 | ERROR   | [ ] Inline comments must end in full-stops, exclamation marks, or question marks
 108 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 108 | ERROR   | [x] Expected exactly one space between closing parenthesis and opening control structure; "
     |         |     " found.
 108 | ERROR   | [x] Inline control structures are not allowed
 108 | ERROR   | [ ] The use of count() inside a loop condition is not allowed; assign the return value to a variable and use the variable in the
     |         |     loop condition instead
 109 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 111 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 112 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 114 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 114 | ERROR   | [ ] Doc comment for parameter "$id" missing
 115 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 116 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 117 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 118 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 119 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 120 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 120 | ERROR   | [ ] Visibility must be declared on method "remove_post"
 121 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 123 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 123 | ERROR   | [x] Inline control structures are not allowed
 123 | WARNING | [ ] Not using strict comparison for in_array; supply true for third argument.
 124 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 126 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 126 | WARNING | [ ] Not using strict comparison for array_search; supply true for third argument.
 128 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 129 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
 133 | ERROR   | [x] Parenthesis should always be used when instantiating a new object.
 135 | ERROR   | [ ] Missing doc comment for function vip_get_hidden_posts()
 136 | ERROR   | [x] Tabs must be used to indent lines; spaces are not allowed
------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 93 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 618ms; Memory: 10MB
nielslange commented 3 years ago

Due to various PRs I created in the previous days, I'd first address the open PRs and merge them, before refactoring the plugin. This allows to refactor the added functionality in one go.

nielslange commented 3 years ago

This issue might be obsolete once #32 had been merged. 🤔

nielslange commented 3 years ago

@trepmal Since you merged #32 yesterday, I checked out the most recent version of this plugin and run composer cs receiving the following result:

$ composer cs                                                                                      
> @php ./vendor/bin/phpcs
E. 2 / 2 (100%)

FILE: tests/bootstrap.php
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 5 ERRORS AFFECTING 4 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1 | ERROR | Missing file doc comment (Squiz.Commenting.FileComment.Missing)
  3 | ERROR | Global variables defined by a theme/plugin should start with the theme/plugin prefix. Found: "$_tests_dir". (WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound)
  5 | ERROR | Global variables defined by a theme/plugin should start with the theme/plugin prefix. Found: "$_tests_dir". (WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound)
 14 | ERROR | Functions declared in the global namespace by a theme/plugin should start with the theme/plugin prefix. Found: "_manually_load_plugin".
    |       | (WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound)
 14 | ERROR | Missing doc comment for function _manually_load_plugin() (Squiz.Commenting.FunctionComment.Missing)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 633ms; Memory: 14MB

Script @php ./vendor/bin/phpcs handling the cs event returned with error code 1

I must have missed these errors when checking #32, and I wonder how you're checking the coding standards. Are you also running composer cs on your end? Shall I go ahead and quickly address the open errors within tests/bootstrap.php?

trepmal commented 3 years ago

You have found my secret, I've been skipping phpcs on the bootstraps in my recent updates :)

Yes, composer cs is what I'm running. (This is notably commented out in the GitHub actions config right now, as it would be pretty noisy until issues get resolved).

You are welcome to address the errors.