Function format_posts_rendering
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
private function format_posts_rendering( $result, $posts ) {
$count = 0;
foreach ( $posts as $post ) {
$values = get_the_terms( $post->ID, 'ldp_container' );
if ( empty( $values[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
File class-container-taxonomy.php
has 256 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Container
*
* The container taxonomy class and instance.
Method add_custom_tax_fields_onedit
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
function add_custom_tax_fields_onedit( $term ) {
$term_id = $term->term_id;
$term_meta = get_option( "ldp_container_$term_id" );
$ldp_model = ! empty( $term_meta['ldp_model'] ) ? stripslashes_deep( $term_meta['ldp_model'] ) : '';
$ldp_rdf_type = isset( $term_meta['ldp_rdf_type'] ) ? $term_meta['ldp_rdf_type'] : '';
Method get_search_results
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function get_search_results( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
header( 'Content-Type: application/ld+json' );
header( 'Access-Control-Allow-Origin: *' );
$params = $request->get_params();
Method get_resources_from_container
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function get_resources_from_container( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
$params = $request->get_params();
$ldp_container = $params['ldp_container'];
$headers = $request->get_headers();
Method register_container_taxonomy
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function register_container_taxonomy() {
$labels = array(
'name' => __( 'Containers', 'wpldp' ),
'singular_name' => __( 'Container', 'wpldp' ),
'menu_name' => __( 'Containers', 'wpldp' ),
Method format_posts_rendering
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function format_posts_rendering( $result, $posts ) {
$count = 0;
foreach ( $posts as $post ) {
$values = get_the_terms( $post->ID, 'ldp_container' );
if ( empty( $values[0] ) ) {
Function save_custom_tax_field
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function save_custom_tax_field( $term_id ) {
$term_meta = get_option( "ldp_container_$term_id" );
if ( ! is_array( $term_meta ) ) {
$term_meta = array();
}
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
$labels = array(
'name' => __( 'Containers', 'wpldp' ),
'singular_name' => __( 'Container', 'wpldp' ),
'menu_name' => __( 'Containers', 'wpldp' ),
'all_items' => __( 'All Items', 'wpldp' ),
- 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 263.
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
public function __construct() {
register_activation_hook( __FILE__, array( $this, 'wpldp_rewrite_flush' ) );
add_action( 'init', array( $this, 'register_container_taxonomy' ), 0 );
add_action( 'ldp_container_add_form_fields', array( $this, 'add_custom_tax_fields_oncreate' ) );
- 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 218.
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
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'. Open
echo "<p class='description'>" . __( 'Rdf:type associated with this container', 'wpldp' ) . '</p>';
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'. Open
echo "<p class='description'>" . __( 'The fields from the model whose values you would like to include from the associated resources in the container, separated by commas', 'wpldp' ) . '</p>';
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'. Open
echo "<p class='description'>" . __( 'The LDP-compatible JSON Model for this container', 'wpldp' ) . '</p>';
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space Open
$posts = $query->get_posts();
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'. Open
echo "<p class='description'>" . __( 'Rdf:type associated with this container', 'wpldp' ) . '</p></td>';
- Exclude checks
Visibility must be declared on method "save_custom_tax_field" Open
function save_custom_tax_field( $term_id ) {
- Exclude checks
Array double arrow not aligned correctly; expected 12 space(s) between "'public'" and double arrow, but found 21. Open
'public' => true,
- Exclude checks
Processing form data without nonce verification. Open
$term_meta['ldp_included_fields_list'] = $_POST['ldp_included_fields_list'];
- Exclude checks
Array double arrow not aligned correctly; expected 2 space(s) between "'methods'" and double arrow, but found 1. Open
'methods' => \WP_REST_Server::READABLE,
- Exclude checks
Array double arrow not aligned correctly; expected 4 space(s) between "'terms'" and double arrow, but found 1. Open
'terms' => $ldp_container,
- Exclude checks
Array double arrow not aligned correctly; expected 1 space(s) between "'show_in_nav_menus'" and double arrow, but found 10. Open
'show_in_nav_menus' => true,
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'. Open
echo "<label for='ldp_model'>" . __( 'Model', 'wpldp' ) . '</label>';
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 16 spaces but found 1 space Open
$term_meta = get_option( "ldp_container_$term_id" );
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'. Open
echo "<p class='description'>" . __( 'The LDP-compatible JSON Model for this container', 'wpldp' ) . '</p></td>';
- Exclude checks
Class file names should be based on the class name with "class-" prepended. Expected class-containertaxonomy.php, but found class-container-taxonomy.php. Open
<?php
- Exclude checks
Array double arrow not aligned correctly; expected 3 space(s) between "'with_front'" and double arrow, but found 17. Open
'with_front' => true,
- Exclude checks
Array double arrow not aligned correctly; expected 11 space(s) between "'show_ui'" and double arrow, but found 20. Open
'show_ui' => true,
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'. Open
echo "<th scope='row'><label for='ldp_included_fields_list'>" . __( 'Included fields', 'wpldp' ) . '</label></th>';
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space Open
$fields = $models_decoded->{$value->slug}->fields;
- Exclude checks
Array double arrow not aligned correctly; expected 6 space(s) between "'hierarchical'" and double arrow, but found 15. Open
'hierarchical' => true,
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 18 spaces but found 1 space Open
$term_id = $term->term_id;
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '"<td>
<input type="text" name="ldp_rdf_type" id="ldp_rdf_type" value="$ldp_rdf_type">"'.</td> Open
echo "<td><input type='text' name='ldp_rdf_type' id='ldp_rdf_type' value='$ldp_rdf_type' />";
- Exclude checks
Missing wp_unslash() before sanitization. Open
$term_meta['ldp_included_fields_list'] = $_POST['ldp_included_fields_list'];
- Exclude checks
Array double arrow not aligned correctly; expected 2 space(s) between "'methods'" and double arrow, but found 1. Open
'methods' => \WP_REST_Server::READABLE,
- Exclude checks
Array double arrow not aligned correctly; expected 5 space(s) between "'show_tagcloud'" and double arrow, but found 14. Open
'show_tagcloud' => true,
- Exclude checks
Visibility must be declared on method "add_custom_tax_fields_oncreate" Open
function add_custom_tax_fields_oncreate( $term ) {
- Exclude checks
Detected usage of a non-sanitized input variable: $_POST Open
$term_meta['ldp_rdf_type'] = $_POST['ldp_rdf_type'];
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'. Open
echo "<label for='ldp_rdf_type'>" . __( 'Rdf:type, if any', 'wpldp' ) . '</label>';
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space Open
$ldp_rdf_type = isset( $term_meta['ldp_rdf_type'] ) ? $term_meta['ldp_rdf_type'] : '';
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space Open
$params = $request->get_params();
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'. Open
echo "<label for='ldp_included_fields_list'>" . __( 'Included fields', 'wpldp' ) . '</label>';
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'. Open
echo "<p class='description'>" . __( 'The fields from the model whose values you would like to include from the associated resources in the container, separated by commas', 'wpldp' ) . '</p></td>';
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '"<input type="hidden" id="ldp_model" name="ldp_model" value="$ldp_model">"'. Open
echo "<input type='hidden' id='ldp_model' name='ldp_model' value='$ldp_model'/>";
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 16 spaces but found 1 space Open
$ldp_model = ! empty( $term_meta['ldp_model'] ) ? stripslashes_deep( $term_meta['ldp_model'] ) : '';
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'. Open
echo "<th scope='row'><label for='ldp_rdf_type'>" . __( 'Rdf:type, if any', 'wpldp' ) . '</label></th>';
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '"<td>
<input type="text" name="ldp_included_fields_list" id="ldp_included_fields_list" value="$ldp_included_fields_list">"'.</td> Open
echo "<td><input type='text' name='ldp_included_fields_list' id='ldp_included_fields_list' value='$ldp_included_fields_list' />";
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'. Open
echo "<th scope='row'><label for='ldp_model_editor'>" . __( 'Model editor mode', 'wpldp' ) . '</label></th>';
- Exclude checks
Array double arrow not aligned correctly; expected 3 space(s) between "'@id'" and double arrow, but found 1. Open
'@id' => rtrim( get_rest_url(), '/' ) . $request->get_route() . '/',
- Exclude checks
Processing form data without nonce verification. Open
$term_meta['ldp_rdf_type'] = $_POST['ldp_rdf_type'];
- Exclude checks
Array double arrow not aligned correctly; expected 12 space(s) between "'labels'" and double arrow, but found 21. Open
'labels' => $labels,
- Exclude checks
Array double arrow not aligned correctly; expected 1 space(s) between "'show_admin_column'" and double arrow, but found 10. Open
'show_admin_column' => true,
- Exclude checks
Array double arrow not aligned correctly; expected 11 space(s) between "'rewrite'" and double arrow, but found 20. Open
'rewrite' => $rewrite,
- Exclude checks
Array double arrow not aligned correctly; expected 6 space(s) between "'post_type'" and double arrow, but found 1. Open
'post_type' => 'ldp_resource',
- Exclude checks
Processing form data without nonce verification. Open
if ( isset( $_POST['ldp_included_fields_list'] ) ) {
- Exclude checks
Array double arrow not aligned correctly; expected 9 space(s) between "'slug'" and double arrow, but found 23. Open
'slug' => rtrim( \WpLdp\Api::LDP_API_URL, '/' ),
- Exclude checks
Processing form data without nonce verification. Open
if ( isset( $_POST['ldp_rdf_type'] ) ) {
- Exclude checks
Array double arrow not aligned correctly; expected 1 space(s) between "'hierarchical'" and double arrow, but found 15. Open
'hierarchical' => false,
- Exclude checks
Visibility must be declared on method "add_custom_tax_fields_onedit" Open
function add_custom_tax_fields_onedit( $term ) {
- Exclude checks
Found precision alignment of 1 spaces. Open
&& false !== strstr( $headers['accept'][0], 'text/html' ) ) {
- Exclude checks
Detected usage of a non-sanitized input variable: $_POST Open
$term_meta['ldp_included_fields_list'] = $_POST['ldp_included_fields_list'];
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space Open
$params = $request->get_params();
- Exclude checks
Detected usage of tax_query, possible slow query. Open
'tax_query' => array(
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space Open
$current_entry = array();
- Exclude checks
Each array item in a multi-line array declaration must end in a comma Open
)
- Exclude checks
Array double arrow not aligned correctly; expected 4 space(s) between "'field'" and double arrow, but found 1. Open
'field' => 'slug',
- Exclude checks
Array double arrow not aligned correctly; expected 6 space(s) between "'post_type'" and double arrow, but found 1. Open
'post_type' => 'ldp_resource',
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space Open
$meta_name = $params['meta_name'];
- Exclude checks
Array double arrow not aligned correctly; expected 6 space(s) between "'tax_query'" and double arrow, but found 1. Open
'tax_query' => array(
- Exclude checks
Detected usage of meta_query, possible slow query. Open
'meta_query' => array(
- Exclude checks
Missing wp_unslash() before sanitization. Open
$term_meta['ldp_rdf_type'] = $_POST['ldp_rdf_type'];
- Exclude checks
Missing wp_unslash() before sanitization. Open
$term_meta['ldp_model'] = stripslashes_deep( $_POST['ldp_model'] );
- Exclude checks
Array double arrow not aligned correctly; expected 6 space(s) between "'tax_query'" and double arrow, but found 1. Open
'tax_query' => array(
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space Open
$meta_value = $params['meta_value'];
- Exclude checks
Detected usage of tax_query, possible slow query. Open
'tax_query' => array(
- Exclude checks
Array double arrow not aligned correctly; expected 3 space(s) between "'@id'" and double arrow, but found 1. Open
'@id' => rtrim( get_rest_url(), '/' ) . $request->get_route() . '/',
- Exclude checks
Array double arrow not aligned correctly; expected 4 space(s) between "'field'" and double arrow, but found 1. Open
'field' => 'slug',
- Exclude checks
json_encode() is discouraged. Use wp_json_encode() instead. Open
var json = ' . json_encode( json_decode( $ldp_model ) ) . ';
- Exclude checks
Array double arrow not aligned correctly; expected 4 space(s) between "'terms'" and double arrow, but found 1. Open
'terms' => $ldp_container,
- Exclude checks
Array double arrow not aligned correctly; expected 5 space(s) between "'key'" and double arrow, but found 1. Open
'key' => $meta_name,
- Exclude checks
Each array item in a multi-line array declaration must end in a comma Open
)
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space Open
$models_decoded = json_decode( $term_meta['ldp_model'] );
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 16 spaces but found 1 space Open
$term_meta = get_option( "ldp_container_$value->term_id" );
- Exclude checks
Processing form data without nonce verification. Open
if ( isset( $_POST['ldp_model'] ) ) {
- Exclude checks
Detected usage of a non-sanitized input variable: $_POST Open
$term_meta['ldp_model'] = stripslashes_deep( $_POST['ldp_model'] );
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space Open
$current_entry['@id'] = site_url( '/' ) . \WpLdp\Api::LDP_API_URL . $value->slug . '/' . $post->post_name;
- Exclude checks
Array double arrow not aligned correctly; expected 5 space(s) between "'meta_query'" and double arrow, but found 1. Open
'meta_query' => array(
- Exclude checks
Array double arrow not aligned correctly; expected 3 space(s) between "'value'" and double arrow, but found 1. Open
'value' => $meta_value,
- Exclude checks
Each array item in a multi-line array declaration must end in a comma Open
)
- Exclude checks
Processing form data without nonce verification. Open
$term_meta['ldp_model'] = stripslashes_deep( $_POST['ldp_model'] );
- Exclude checks
Each array item in a multi-line array declaration must end in a comma Open
)
- Exclude checks
Each array item in a multi-line array declaration must end in a comma Open
)
- Exclude checks