MatthewMi11er/wordpress-plugin-mi11er-utility

View on GitHub
includes/mi11er-utility/class-template-tags.php

Summary

Maintainability
A
2 hrs
Test Coverage

Consider simplifying this complex logical expression.
Open

            if ( $offset > 0 && $offset + mb_strlen( $matches[0], 'UTF-8' ) !== mb_strlen( $title, 'UTF-8' )
                && preg_match( $small_words, $matches[0] ) && ( $offset - 2 < 0 || mb_substr( $title, $offset - 2, 1 , 'UTF-8' ) !== ':' )
                && ( mb_substr( $title, $offset + mb_strlen( $matches[0], 'UTF-8' ), 1 ) !== '-'
                    || $offset - 1 < 0 || mb_substr( $title, $offset - 1, 1, 'UTF-8' ) === '-' )
                && ( $offset - 1 < 0 || ! preg_match( '/[^\s-]/', mb_substr( $title, $offset - 1, 1, 'UTF-8' ) ) ) ) {
Severity: Critical
Found in includes/mi11er-utility/class-template-tags.php - About 2 hrs to fix

Avoid too many return statements within this method.
Open

        return $home_url;
Severity: Major
Found in includes/mi11er-utility/class-template-tags.php - About 30 mins to fix

The method to_title_case() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
Open

    public static function to_title_case( $title ) {
        /**
         * Remove HTML like tags and entities
         */
        $elements = '/<(code|var)[^>]*>.*?<\/\1>|<[^>]+>|&\S+;/';

CyclomaticComplexity

Since: 0.1

Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

Example

// Cyclomatic Complexity = 11
class Foo {
1   public function example() {
2       if ($a == $b) {
3           if ($a1 == $b1) {
                fiddle();
4           } elseif ($a2 == $b2) {
                fiddle();
            } else {
                fiddle();
            }
5       } elseif ($c == $d) {
6           while ($c == $d) {
                fiddle();
            }
7        } elseif ($e == $f) {
8           for ($n = 0; $n < $h; $n++) {
                fiddle();
            }
        } else {
            switch ($z) {
9               case 1:
                    fiddle();
                    break;
10              case 2:
                    fiddle();
                    break;
11              case 3:
                    fiddle();
                    break;
                default:
                    fiddle();
                    break;
            }
        }
    }
}

Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

Missing class import via use statement (line '55', column '14').
Open

            throw new \InvalidArgumentException( 'Function for `'. $tag . '` tag must be callable' );

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

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

Missing class import via use statement (line '34', column '14').
Open

            throw new \BadFunctionCallException( $tag . ' not defined' );

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

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

Missing class import via use statement (line '51', column '14').
Open

            throw new \RuntimeException( 'Template Tag already defined' );

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

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

The property $_tags is not named in camelCase.
Open

class Template_Tags
{
    /**
     * Tags that have been added
     *

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 Template_Tags is not named in CamelCase.
Open

class Template_Tags
{
    /**
     * Tags that have been added
     *

CamelCaseClassName

Since: 0.2

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

Example

class class_name {
}

Source

The method the_template_directory_uri is not named in camelCase.
Open

    public static function the_template_directory_uri( $path = '', $scheme = null ) {
        if ( ! is_string( $path ) ) {
            $path = '';
        }
        echo esc_url( set_url_scheme( trailingslashit( get_template_directory_uri() ) . ltrim( $path, '/' ), $scheme ) );

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

    public static function the_home_url( $path = '', $scheme = null ) {
        echo esc_url( self::home_url( $path, $scheme ) );
    }

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

    public static function get_mu_template_directory() {
        return dirname( dirname( __DIR__ ) ) . DIRECTORY_SEPARATOR . 'templates';
    }

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

    public static function get_the_request_url() {
        // Deterimine if wordpress root is in a subdir.
        $home_path = wp_parse_url( home_url() )['path'];
        if ( ! is_string( $home_path ) ) {
            $home_path = '/';

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

    public static function home_url( $path = '', $scheme = null ) {
        $home_url = home_url( $path, $scheme );
        if ( ! empty( $path ) ) {
            return $home_url;
        }

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

    public static function add_tag( $tag, $function ) {
        if ( array_key_exists( $tag, self::$_tags ) ) {
            throw new \RuntimeException( 'Template Tag already defined' );
        }

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

    public static function get_the_root_directory() {
        $home    = set_url_scheme( get_option( 'home', '' ), 'http' );
        $siteurl = set_url_scheme( get_option( 'siteurl', '' ), 'http' );
        if ( '' === $home  || 0 === strcasecmp( $home, $siteurl ) ) {
            return ABSPATH;

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

    public static function to_title_case( $title ) {
        /**
         * Remove HTML like tags and entities
         */
        $elements = '/<(code|var)[^>]*>.*?<\/\1>|<[^>]+>|&\S+;/';

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