Showing 47 of 47 total issues
Identical blocks of code found in 2 locations. Consider refactoring. Open
foreach( $endpoints as $endpoint ) {
// Add yes/no options to remove the endpoint.
$name = 'remove-endpoint|/' . $namespace . '/' . $endpoint;
add_settings_field( $name, sprintf( __( '%s', 'rest-api-toolbox' ), $endpoint),
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 180.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
foreach( $endpoints as $endpoint ) {
// Add yes/no options to remove the endpoint.
$name = 'remove-endpoint|/' . $namespace . '/' . $endpoint;
add_settings_field( $name, sprintf( __( '%s', 'rest-api-toolbox' ), $endpoint),
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 180.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Function exports
has 105 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function( grunt ) {
'use strict';
var banner = '/**\n * <%= pkg.homepage %>\n * Copyright (c) <%= grunt.template.today("yyyy") %>\n * This file is generated automatically. Do not edit.\n */\n';
// Project configuration
Similar blocks of code found in 2 locations. Consider refactoring. Open
function enable( $positional_args, $assoc_args = array() ) {
if ( ! empty( $positional_args ) ) {
$core_endpoint = $positional_args[0];
if ( ! in_array( $core_endpoint, REST_API_Toolbox_Common::core_endpoints() ) ) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 165.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
function disable( $positional_args, $assoc_args = array() ) {
if ( ! empty( $positional_args ) ) {
$core_endpoint = $positional_args[0];
if ( ! in_array( $core_endpoint, REST_API_Toolbox_Common::core_endpoints() ) ) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 165.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Function endpoint_requires_authentication_filter
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
static public function endpoint_requires_authentication_filter( $result, $rest_server, $request ) {
// Get the route for the request.
$route = $request->get_route();
- Read upRead up
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
The class REST_API_Toolbox_Common has 14 public methods. Consider refactoring REST_API_Toolbox_Common to keep number of public methods under 10. Open
class REST_API_Toolbox_Common {
static public function plugins_loaded() {
// Setup disabled filter based on the changing in WP 4.7
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
The class REST_API_Toolbox_Common has an overall complexity of 57 which is very high. The configured complexity threshold is 50. Open
class REST_API_Toolbox_Common {
static public function plugins_loaded() {
// Setup disabled filter based on the changing in WP 4.7
- Exclude checks
Function remove_selected_endpoints_filter
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
static public function remove_selected_endpoints_filter( $routes ) {
// Get the list of core endpoints.
$core_settings = get_option( REST_API_Toolbox_Settings::options_key( 'core' ) );
$core_settings = ! is_array( $core_settings ) ? array() : $core_settings;
- Read upRead up
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
Function remove_wordpress_core_namespace_filter
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
static public function remove_wordpress_core_namespace_filter( $response ) {
$remove_all = REST_API_Toolbox_Settings::setting_is_enabled( 'core', 'remove-all-core-routes' );
if ( $remove_all ) {
if ( ! empty( $response->data ) && ! empty( $response->data['namespaces'] ) ) {
- Read upRead up
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
Method settings_input
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
static public function settings_input( $args ) {
$args = wp_parse_args( $args,
array(
'name' => '',
Avoid excessively long class names like REST_API_Toolbox_Settings_Custom_Post_Types. Keep class name length under 40. Open
class REST_API_Toolbox_Settings_Custom_Post_Types extends REST_API_Toolbox_Settings_Base {
static $settings_key = 'rest-api-toolbox-settings-cpt';
/**
- Read upRead up
- Exclude checks
LongClassName
Since: 2.9
Detects when classes or interfaces are declared with excessively long names.
Example
class ATooLongClassNameThatHintsAtADesignProblem {
}
interface ATooLongInterfaceNameThatHintsAtADesignProblem {
}
Source https://phpmd.org/rules/naming.html#longclassname
Function status
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
function status( $positional_args, $assoc_args = array() ) {
if ( ! empty( $positional_args ) ) {
$core_endpoint = $positional_args[0];
- Read upRead up
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
Method register_cpt_settings
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
static public function register_cpt_settings() {
$key = self::$settings_key;
register_setting( $key, $key, array( __CLASS__, 'sanitize_cpt_settings') );
Method endpoint_requires_authentication_filter
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
static public function endpoint_requires_authentication_filter( $result, $rest_server, $request ) {
// Get the route for the request.
$route = $request->get_route();
Method register_core_settings
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
static public function register_core_settings() {
$key = self::$settings_key;
register_setting( $key, $key, array( __CLASS__, 'sanitize_core_settings') );
Method settings_yes_no
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
static public function settings_yes_no( $args ) {
$args = wp_parse_args( $args,
array(
'name' => '',
Avoid deeply nested control flow statements. Open
if ( self::core_namespace() === $response->data['namespaces'][ $i ] ) {
unset( $response->data['namespaces'][ $i ] );
$response->data['namespaces'] = array_values( $response->data['namespaces'] );
break;
}
Function register_cpt_settings
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
static public function register_cpt_settings() {
$key = self::$settings_key;
register_setting( $key, $key, array( __CLASS__, 'sanitize_cpt_settings') );
- Read upRead up
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
Missing class import via use statement (line '163', column '22'). Open
$response = new WP_Error( 'rest_forbidden', __( "SSL is required to access the REST API" ), array( 'status' => 403 ) );
- Read upRead up
- Exclude checks
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();
}