MatthewMi11er/wordpress-plugin-mi11er-utility

View on GitHub
includes/mi11er-utility/class-file-handler.php

Summary

Maintainability
A
1 hr
Test Coverage

Method the_posts_filter has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function the_posts_filter( $posts, $wp_query ) {
        $file_config = $this->get_config();
        if ( false !== $file_config && $wp_query->is_main_query() && ! is_admin() ) {
            $default_post = [
                'post_author'    => 1,
Severity: Minor
Found in includes/mi11er-utility/class-file-handler.php - About 1 hr to fix

Method add_config has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function add_config( $file, $rewrite, $template, $prevent_slash = true, $post = [] ) {
Severity: Minor
Found in includes/mi11er-utility/class-file-handler.php - About 35 mins to fix

The method add_config has a boolean flag argument $prevent_slash, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function add_config( $file, $rewrite, $template, $prevent_slash = true, $post = [] ) {

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

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

Avoid assigning values to variables in if clauses and the like (line '106', column '18').
Open

    public function template_include_filter( $template ) {
        // Check if we're dealing stuff care about.
        if ( false !== $file_config = $this->get_config() ) {
            return $file_config['template'];
        }

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

Avoid unused parameters such as '$requested_url'.
Open

    public function redirect_canonical_filter( $redirect_url, $requested_url ) {

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

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

The parameter $requested_url is not named in camelCase.
Open

    public function redirect_canonical_filter( $redirect_url, $requested_url ) {
        // Check if we're dealing stuff we care about and optionally prevent addtion of trailing slash.
        if ( false !== $this->get_config() && $this->get_config()['prevent_slash'] ) {
            return false;
        }

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 property $_files is not named in camelCase.
Open

class File_Handler implements Plugin_Interface
{
    /**
     * List of files that this plugin will handle.
     *

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

The class File_Handler is not named in CamelCase.
Open

class File_Handler implements Plugin_Interface
{
    /**
     * List of files that this plugin will handle.
     *

CamelCaseClassName

Since: 0.2

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

Example

class class_name {
}

Source

The parameter $wp_query is not named in camelCase.
Open

    public function the_posts_filter( $posts, $wp_query ) {
        $file_config = $this->get_config();
        if ( false !== $file_config && $wp_query->is_main_query() && ! is_admin() ) {
            $default_post = [
                'post_author'    => 1,

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 parameter $redirect_url is not named in camelCase.
Open

    public function redirect_canonical_filter( $redirect_url, $requested_url ) {
        // Check if we're dealing stuff we care about and optionally prevent addtion of trailing slash.
        if ( false !== $this->get_config() && $this->get_config()['prevent_slash'] ) {
            return false;
        }

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 parameter $prevent_slash is not named in camelCase.
Open

    public function add_config( $file, $rewrite, $template, $prevent_slash = true, $post = [] ) {
        $this->_files[] = [
            'file'          => $file,
            'rewrite'       => $rewrite,
            'template'      => $template,

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 method get_config is not named in camelCase.
Open

    public function get_config() {
        $file_key = get_query_var( 'mu_file_handler', false );
        if ( false !== $file_key && array_key_exists( $file_key, $this->_files ) ) {
            return $this->_files[ $file_key ];
        }

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

The method redirect_canonical_filter is not named in camelCase.
Open

    public function redirect_canonical_filter( $redirect_url, $requested_url ) {
        // Check if we're dealing stuff we care about and optionally prevent addtion of trailing slash.
        if ( false !== $this->get_config() && $this->get_config()['prevent_slash'] ) {
            return false;
        }

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

The method template_include_filter is not named in camelCase.
Open

    public function template_include_filter( $template ) {
        // Check if we're dealing stuff care about.
        if ( false !== $file_config = $this->get_config() ) {
            return $file_config['template'];
        }

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

The method add_config is not named in camelCase.
Open

    public function add_config( $file, $rewrite, $template, $prevent_slash = true, $post = [] ) {
        $this->_files[] = [
            'file'          => $file,
            'rewrite'       => $rewrite,
            'template'      => $template,

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

The method the_posts_filter is not named in camelCase.
Open

    public function the_posts_filter( $posts, $wp_query ) {
        $file_config = $this->get_config();
        if ( false !== $file_config && $wp_query->is_main_query() && ! is_admin() ) {
            $default_post = [
                'post_author'    => 1,

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

The method init_action is not named in camelCase.
Open

    public function init_action() {
        /**
         * Fires on WordPress init, other themes and plugins to use this to handle their files.
         *
         * @param File_Handler $this File_Handler instance.

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