WPBP / WordPress-Plugin-Boilerplate-Powered

Wordpress Plugin Boilerplate but Powered with examples and a generator!
https://wpbp.github.io/
GNU General Public License v3.0
793 stars 114 forks source link

PHPMD Errors #155

Closed MikeiLL closed 4 years ago

MikeiLL commented 4 years ago

I'm new to PHPMD. Love it.

Getting the following (cool picture and) errors:

             ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
           ▄▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
         ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄
        ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
       ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
  ▄███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
 █▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
 ▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
   ▀█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
     ▀▀▓▓▓▓▓▓▓▓▓▓▓▓█▀▀▀▀▀▀▀▀▀▀▀▀▀▀████████████▄
      ▄███████                       ██████████
     ███████▀  ▀▀▀▀▀▄      ▄▀▀▀▀▀     █████ ▀
      ▐████      ▐██        ▐██        ████▌
      ████▌                            ███
       ▌██▌           ▄▄ ▄▄           ▐███
        ███       ▄▄▄▄▄▄▄▄▄▄▄▄       ▐███
         ██▄ ▐███████████████████████████
        █▀███████████▀     ▀▀███████████
          ██████████▄███████▄███████████
         ▐█████████████████████████████
          █████████████████████████████
           ██ █████████████████████▐██▀
            ▀ ▐███████████████████▌ ▐▀
                ████▀████████▀▐███
                 ▀█▌  ▐█████  ██▌
                        ██▀   ▐▀

       ██████████████████████████████████
       █░░░░░░▀█▀░░░░░░▀█░░░░░░▀█▀░░░░░▀█
       █░░▐█▌░░█░░░██░░░█░░██░░░█░░░██░░█
       █░░▐█▌░░█░░░██░░░█░░██░░░█░░░██░░█
       █░░▐█▌░░█░░░██░░░█░░░░░░▄█░░▄▄▄▄▄█
       █░░▐█▌░░█░░░██░░░█░░░░████░░░░░░░█
       █░░░█░░░█▄░░░░░░▄█░░░░████▄░░░░░▄█
       ██████████████████████████████████

/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/backend/ImpExp.php:57 Avoid using undefined variables such as '$settings' which will lead to PHP notices.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/backend/ImpExp.php:58 Avoid using undefined variables such as '$settings' which will lead to PHP notices.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/backend/ImpExp.php:67 Avoid using undefined variables such as '$settings' which will lead to PHP notices.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/backend/ImpExp.php:116    Missing class import via use statement (line '116', column '7').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/backend/Notices.php:37    Missing class import via use statement (line '37', column '7').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/backend/Pointers.php:30   Missing class import via use statement (line '30', column '7').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/cli/Example.php:44    Avoid using static access to class '\WP_CLI' in method '__construct'.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/cli/Example.php:59    Avoid using static access to class '\WP_CLI' in method 'command_example'.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/cli/Example.php:61    Avoid using static access to class '\WP_CLI' in method 'command_example'.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/cli/Example.php:63    Avoid using static access to class '\WP_CLI' in method 'command_example'.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/cli/Example.php:65    Avoid using static access to class '\WP_CLI' in method 'command_example'.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/cli/Example.php:67    Avoid using static access to class '\WP_CLI' in method 'command_example'.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/cli/Example.php:69    Avoid using static access to class '\WP_CLI' in method 'command_example'.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/cli/Example.php:71    Avoid using static access to class '\WP_CLI' in method 'command_example'.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/engine/Initialize.php:25  Avoid variables with short names like $is. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/engine/Initialize.php:86  Avoid using undefined variables such as '$class' which will lead to PHP notices.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/engine/Initialize.php:88  Missing class import via use statement (line '88', column '17').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/engine/Initialize.php:88  Avoid using undefined variables such as '$class' which will lead to PHP notices.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/engine/Initialize.php:93  Missing class import via use statement (line '93', column '16').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/integrations/CMB.php:53   Missing class import via use statement (line '53', column '19').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/integrations/Cron.php:38  Missing class import via use statement (line '38', column '19').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/integrations/Cron.php:56  Avoid variables with short names like $id. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/integrations/FakePage.php:28  Missing class import via use statement (line '28', column '13').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/integrations/Widgets/My_Recent_Posts_Widget.php:23    The method __construct() has 125 lines of code. Current threshold is set to 100. Avoid really long methods.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/internals/PostTypes.php:32    Missing class import via use statement (line '32', column '23').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/internals/PostTypes.php:50    Missing class import via use statement (line '50', column '23').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/internals/Transient.php:68    Avoid using undefined variables such as '$value' which will lead to PHP notices.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/rest/Example.php:122  Missing class import via use statement (line '122', column '24').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/acceptance/AdminEnqueueCest.php:4   Avoid variables with short names like $I. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/acceptance/AdminEnqueueCest.php:10  Avoid variables with short names like $I. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/acceptance/AdminEnqueueCest.php:17  Avoid variables with short names like $I. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/acceptance/AdminSettingsJsCest.php:4    Avoid variables with short names like $I. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/acceptance/AdminSettingsJsCest.php:9    Avoid variables with short names like $I. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/acceptance/AdminSettingsPageCest.php:Avoid variables with short names like $I. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/acceptance/AdminSettingsPageCest.php:Avoid variables with short names like $I. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/acceptance/AdminSettingsPageCest.php:15 Avoid variables with short names like $I. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/functional/CliCest.php:10   Avoid variables with short names like $I. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/functional/CustomRestRouteCest.php:6    Avoid variables with short names like $I. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/functional/CustomRestRouteCest.php:13Avoid variables with short names like $I. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/functional/CustomRestRouteCest.php:24Avoid variables with short names like $I. Configured minimum length is 3.
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/wpunit/ajax/AdminAjaxTest.php:26    Missing class import via use statement (line '26', column '14').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/wpunit/ajax/AjaxTest.php:24 Missing class import via use statement (line '24', column '14').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/wpunit/engine/InitializeAdminTest.php:27    Missing class import via use statement (line '27', column '14').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/wpunit/engine/InitializeTest.php:27 Missing class import via use statement (line '27', column '14').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/tests/wpunit/public/ExtrasTest.php:26 Missing class import via use statement (line '26', column '14').
/Users/mikekilmer/Docker/WP/mzmbo/mz-mindbody-classes/uninstall.php:92  Missing class import via use statement (line '92', column '19').
You have blacklisted keywords in your commit:
backend/ImpExp.php
  1:20: 95:         wp_die( esc_html__( 'Ple
  2:20: 101:            wp_die( esc_html__( 'Ple
engine/Initialize.php
  5:20: 132:                wp_die( esc_html__( 'Plu
mz-mindbody-classes.php
  8:20: 26: die( 'We\'re sorry, b

Do you recommend I ignore some of that in a config file, fix them? Thanks.

Mte90 commented 4 years ago

Some of these errors is on you to ignore it or fix it. I use this https://github.com/CodeAtCode/CodeatCS/blob/master/codeat-phpmd.xml config file for phpmd. About the blacklisted words again it is on you if follow them or not.

MikeiLL commented 4 years ago

To suppress warnings: https://phpmd.org/documentation/suppress-warnings.html

MikeiLL commented 4 years ago

Some of these errors is on you to ignore it or fix it. I use this https://github.com/CodeAtCode/CodeatCS/blob/master/codeat-phpmd.xml config file for phpmd. About the blacklisted words again it is on you if follow them or not.

Where does that file go? I have tried in the main plugin directory under the names phpmd.xml, codeat-phpmd.xml and ruleset.xml. Also tried phpmd.xml in my home directory, where composer is configured.

Mte90 commented 4 years ago

You need to pass to phpmd as written at https://phpmd.org/documentation/index.html

MikeiLL commented 4 years ago

You need to pass to phpmd as written at https://phpmd.org/documentation/index.html

It's being triggered by git commit.

Mte90 commented 4 years ago

So you need to configure grumphp.yml and check grumphp settings.

MikeiLL commented 4 years ago

Got the blacklist error to go away.

But the ruleset from your link isn't making the list of warnings go away.

#grumphp.yml
---
parameters:
  git_dir: .
  bin_dir: composer/bin
  ignore_unstaged_changes: false
  tasks:
    composer:
      with_dependencies: false
      strict: false
    phpmd:
      ruleset: ['phpmd.xml']
      triggered_by: 
      - php
    git_blacklist:
      keywords:
      - print_r(
      - var_dump(
      triggered_by:
      - php

And in same directory:

#phpmd.xml
<?xml version="1.0"?>
<ruleset name="Standard PHPMD"
         xmlns="http://pmd.sf.net/ruleset/1.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
                     http://pmd.sf.net/ruleset_xml_schema.xsd"
         xsi:noNamespaceSchemaLocation="
                     http://pmd.sf.net/ruleset_xml_schema.xsd">
    <description>
        Standard PHPMD
    </description>

    <rule ref="rulesets/cleancode.xml"  >
        <exclude name="MissingImport"/>
    </rule>
    <rule ref="rulesets/codesize.xml" />
    <rule ref="rulesets/design.xml" />
    <rule ref="rulesets/naming.xml" />
    <rule ref="rulesets/unusedcode.xml" >
        <exclude name="UnusedLocalVariable"/>
        <exclude name="UnusedFormalParameter"/>
    </rule>

    <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable">
        <priority>1</priority>
        <properties>
            <property name="allow-unused-foreach-variables" value="true" />
        </properties>
    </rule>

    <!-- @see https://github.com/phpmd/phpmd/issues/279 -->
    <exclude-pattern>index.php</exclude-pattern>

</ruleset>

Do I need to make copies of the rulesets from vendor/phpmd?

MikeiLL commented 4 years ago

Not sure if this is the expected fix, but I copied the resources/rulesets from vendor/phpmd and made modifications so that the errors went away.

             ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
           ▄▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌           
         ▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
        ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
        ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌        
  ▄▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
 ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌        
 ▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌        
   ▀█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌        
     ▀▀▓▓▓▓▓▓▓▓▓▓▓▓█▀▀▀▀▀▀▀▀▀▀▀▀▀▀████████████▄
      ▄████████▀▀▀▀▀                 ██████████   
     ███████▀                         ██████▀
      ▐████      ██▌          ██       ████▌      
        ▐█▌                            ███        
         █▌           ▄▄ ▄▄           ▐███        
        ███       ▄▄▄▄▄▄▄▄▄▄▄▄       ▐███         
         ██▄ ▐███████████████████████████
        █▀█████████▌▀▀▀▀▀▀▀▀▀██████████▌▐         
          ███████████▄▄▄▄▄▄▄███████████▌          
         ▐█████████████████████████████           
          █████████████████████████████           
           ██ █████████████████████▐██▀           
            ▀ ▐███████████████████▌ ▐▀            
                ████▀████████▀▐███                
                 ▀█▌  ▐█████  ▐█▌                 
                        ██▀   ▐▀                  
       _    _ _                         _ _
      / \  | | |   __ _  ___   ___   __| | |
     / _ \ | | |  / _` |/ _ \ / _ \ / _` | |
    / ___ \| | | | (_| | (_) | (_) | (_| |_|
   /_/   \_\_|_|  \__, |\___/ \___/ \__,_(_)
                  |___/
[master 33afd7a] Barebones phpmd configs to make warnings go away.
 7 files changed, 1574 insertions(+)
 create mode 100644 phpmd.xml
 create mode 100644 rulesets/cleancode.xml
 create mode 100644 rulesets/codesize.xml
 create mode 100644 rulesets/controversial.xml
 create mode 100644 rulesets/design.xml
 create mode 100644 rulesets/naming.xml
 create mode 100644 rulesets/unusedcode.xml

I would think that the generated (or cloned) boilerplate files should also contain phpmd.xml and rulesets by which the codebase will be passing. Maybe this learning curve is part of what you are going for.

I'm not sure if this current project is going to warrant testing, but I'm excited to get into Codeception.

Mte90 commented 4 years ago

Copy the ruleset isn't a good practice because they can change etc, the best way instead is to disable the one that you down want. Usually for phpmd the ruleset aren't project based like phpcs more global so don't define them in the boilerplate is a way to let people customize by their needs. Anyway I think that I can do some changes for that.

MikeiLL commented 4 years ago

Usually for phpmd the ruleset aren't project based like phpcs more global so don't define them in the boilerplate is a way to let people customize by their needs.

If they are global, do the configuration files go in your home directory, as opposed to the plugin directory?

Mte90 commented 4 years ago

This is on you, I suggest to you to check the phpmd documentation and set as you prefer