lesterchan/wp-sweep

View on GitHub
inc/class-wpsweep-command.php

Summary

Maintainability
A
2 hrs
Test Coverage

Method __invoke has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function __invoke( $args, $assoc_args ) {

        $items = array();

        $default_items = array(
Severity: Minor
Found in inc/class-wpsweep-command.php - About 1 hr to fix

    Function __invoke has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        public function __invoke( $args, $assoc_args ) {
    
            $items = array();
    
            $default_items = array(
    Severity: Minor
    Found in inc/class-wpsweep-command.php - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid unused local variables such as '$key'.
    Open

                foreach ( $default_items as $key => $item ) {
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    UnusedLocalVariable

    Since: 0.2

    Detects when a local variable is declared and/or assigned, but not used.

    Example

    class Foo {
        public function doSomething()
        {
            $i = 5; // Unused
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

    Avoid unused local variables such as '$key'.
    Open

            foreach ( $items as $key => $value ) {
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    UnusedLocalVariable

    Since: 0.2

    Detects when a local variable is declared and/or assigned, but not used.

    Example

    class Foo {
        public function doSomething()
        {
            $i = 5; // Unused
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

    Avoid using static access to class 'WP_CLI' in method '__invoke'.
    Open

                WP_CLI::success( 'Sweep Complete' );
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    The method __invoke uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                foreach ( $default_items as $key => $item ) {
                    if ( in_array( $item, $args, true ) ) {
                        array_push( $items, $item );
                    }
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

    Avoid using static access to class 'WPSweep' in method 'run_sweep'.
    Open

            $sweep = WPSweep::get_instance();
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class 'WP_CLI' in method '__invoke'.
    Open

                WP_CLI::success( 'Sweep Complete!' );
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class 'WP_CLI' in method 'run_sweep'.
    Open

                    WP_CLI::success( $message );
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    The parameter $assoc_args is not named in camelCase.
    Open

        public function __invoke( $args, $assoc_args ) {
    
            $items = array();
    
            $default_items = array(
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    CamelCaseParameterName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name parameters.

    Example

    class ClassName {
        public function doSomething($user_name) {
        }
    }

    Source

    The class WPSweep_Command is not named in CamelCase.
    Open

    class WPSweep_Command extends WP_CLI_Command {
        /**
         * Clean up unused, orphaned and duplicated data in your WordPress
         *
         * ## OPTIONS
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    CamelCaseClassName

    Since: 0.2

    It is considered best practice to use the CamelCase notation to name classes.

    Example

    class class_name {
    }

    Source

    The variable $assoc_args is not named in camelCase.
    Open

        public function __invoke( $args, $assoc_args ) {
    
            $items = array();
    
            $default_items = array(
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $default_items is not named in camelCase.
    Open

        public function __invoke( $args, $assoc_args ) {
    
            $items = array();
    
            $default_items = array(
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $assoc_args is not named in camelCase.
    Open

        public function __invoke( $args, $assoc_args ) {
    
            $items = array();
    
            $default_items = array(
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $default_items is not named in camelCase.
    Open

        public function __invoke( $args, $assoc_args ) {
    
            $items = array();
    
            $default_items = array(
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $default_items is not named in camelCase.
    Open

        public function __invoke( $args, $assoc_args ) {
    
            $items = array();
    
            $default_items = array(
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The method run_sweep is not named in camelCase.
    Open

        public function run_sweep( $items ) {
    
            $sweep = WPSweep::get_instance();
    
            foreach ( $items as $key => $value ) {
    Severity: Minor
    Found in inc/class-wpsweep-command.php by phpmd

    CamelCaseMethodName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name methods.

    Example

    class ClassName {
        public function get_name() {
        }
    }

    Source

    There are no issues that match your filters.

    Category
    Status