Function get_sites_list
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public function get_sites_list( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
header( 'Content-Type: application/ld+json' );
header( 'Access-Control-Allow-Origin: *' );
$terms = get_terms(
- 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 get_sites_list
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function get_sites_list( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
header( 'Content-Type: application/ld+json' );
header( 'Access-Control-Allow-Origin: *' );
$terms = get_terms(
Method register_site_taxonomy
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function register_site_taxonomy() {
$labels = array(
'name' => __( 'Sites', 'wpldp' ),
'singular_name' => __( 'Site', 'wpldp' ),
'menu_name' => __( 'Sites', 'wpldp' ),
Similar blocks of code found in 2 locations. Consider refactoring. Open
$labels = array(
'name' => __( 'Sites', 'wpldp' ),
'singular_name' => __( 'Site', 'wpldp' ),
'menu_name' => __( 'Sites', '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_site_taxonomy' ), 0 );
add_action( 'ldp_site_add_form_fields', array( $this, 'add_custom_tax_fields_oncreate_site' ) );
- 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
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
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space Open
$ch = curl_init();
- Exclude checks
Array double arrow not aligned correctly; expected 3 space(s) between "'taxonomy'" and double arrow, but found 1. Open
'taxonomy' => 'ldp_site',
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space Open
$term_id = $term->term_id;
- Exclude checks
Concat operator must be surrounded by a single space Open
echo "<p class='description'>" . __( 'WordPress site that you know and that the WP-LDP plugin is installed', 'wpldp' ). '</p>';
- Exclude checks
Concat operator must be surrounded by a single space Open
echo "<th scope='row'><label for='ldp_site_url'>" . __( 'web site', 'wpldp' ). '</label></th>';
- Exclude checks
Visibility must be declared on method "save_custom_tax_field_site" Open
function save_custom_tax_field_site( $term_id ) {
- Exclude checks
Using cURL functions is highly discouraged. Use wp_remote_get() instead. Open
curl_setopt( $ch, CURLOPT_URL, $build_url );
- Exclude checks
Array double arrow not aligned correctly; expected 3 space(s) between "'taxonomy'" and double arrow, but found 1. Open
'taxonomy' => 'ldp_site',
- Exclude checks
Using cURL functions is highly discouraged. Use wp_remote_get() instead. Open
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/ld+json', 'Accept: application/ld+json' ) );
- Exclude checks
Array double arrow not aligned correctly; expected 31 space(s) between "'@id'" and double arrow, but found 6. Open
'@id' => get_site_url() . '/api/ldp/v1/sites/',
- Exclude checks
Using cURL functions is highly discouraged. Use wp_remote_get() instead. Open
$outputs[ $ldp_site_url . '/schema/' ]['code'] = curl_getinfo( $ch )['http_code'];
- Exclude checks
No space after opening parenthesis is prohibited Open
foreach ($outputs as $site_url => $output ) {
- Exclude checks
Concat operator must be surrounded by a single space Open
echo "<p class='description'>" . __( 'WordPress site that you know and on which the WP-LDP plugin is installed', 'wpldp' ). '</p></td>';
- Exclude checks
Detected usage of meta_query, possible slow query. Open
'meta_query' => array(
- 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
Using cURL functions is highly discouraged. Use wp_remote_get() instead. Open
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
- Exclude checks
Concat operator must be surrounded by a single space Open
$outputs[ $ldp_site_url . '/schema/' ]['data'] = curl_exec( $ch );
- Exclude checks
Expected type hint "{\WP_REST_Request}"; found "\WP_REST_Request" for $request Open
public function add_new_site( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
- 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
Visibility must be declared on method "add_custom_tax_fields_onedit_site" Open
function add_custom_tax_fields_onedit_site( $term ) {
- Exclude checks
Processing form data without nonce verification. Open
if ( isset( $_POST['ldp_site_url'] ) ) {
- Exclude checks
Detected usage of a non-sanitized input variable: $_POST Open
$term_meta = $_POST['ldp_site_url'];
- Exclude checks
Missing wp_unslash() before sanitization. Open
$term_meta = $_POST['ldp_site_url'];
- Exclude checks
Array double arrow not aligned correctly; expected 3 space(s) between "'value'" and double arrow, but found 1. Open
'value' => $source_site_url,
- 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
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'. Open
echo "<p class='description'>" . __( 'WordPress site that you know and on which the WP-LDP plugin is installed', 'wpldp' ). '</p></td>';
- Exclude checks
Expected type hint "{\WP_REST_Response}"; found "\WP_REST_Response" for $response Open
public function add_new_site( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
- Exclude checks
Array double arrow not aligned correctly; expected 9 space(s) between "'slug'" and double arrow, but found 23. Open
'slug' => 'site',
- 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
Array double arrow not aligned correctly; expected 11 space(s) between "'rewrite'" and double arrow, but found 20. Open
'rewrite' => $rewrite,
- Exclude checks
Using cURL functions is highly discouraged. Use wp_remote_get() instead. Open
$ch = curl_init();
- Exclude checks
Using cURL functions is highly discouraged. Use wp_remote_get() instead. Open
$outputs[ $ldp_site_url . '/schema/' ]['data'] = curl_exec( $ch );
- Exclude checks
Using cURL functions is highly discouraged. Use wp_remote_get() instead. Open
curl_setopt( $ch, CURLOPT_HTTPGET, true );
- 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
Array double arrow not aligned correctly; expected 29 space(s) between "'@type'" and double arrow, but found 4. Open
'@type' => 'http://www.w3.org/ns/ldp#BasicContainer',
- 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_site'>" . __( 'web site', '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'>" . __( 'WordPress site that you know and that the WP-LDP plugin is installed', 'wpldp' ). '</p>';
- 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 1 space(s) between "'hierarchical'" and double arrow, but found 15. Open
'hierarchical' => false,
- 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
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space Open
$term_meta = get_term_meta( $term_id,'ldp_site_url', true );
- Exclude checks
Processing form data without nonce verification. Open
$term_meta = $_POST['ldp_site_url'];
- Exclude checks
Concat operator must be surrounded by a single space Open
$outputs[ $ldp_site_url . '/schema/' ]['code'] = curl_getinfo( $ch )['http_code'];
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space Open
$current_site = $response->{'@graph'}[0];
- Exclude checks
Class file names should be based on the class name with "class-" prepended. Expected class-sitetaxonomy.php, but found class-site-taxonomy.php. Open
<?php
- Exclude checks
Expected 2 spaces after parameter type; 1 found Open
* @param {\WP_REST_Request} $request The current HTTP request object.
- 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::CREATABLE,
- 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
Array double arrow not aligned correctly; expected 5 space(s) between "'key'" and double arrow, but found 1. Open
'key' => 'ldp_site_url',
- 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
Visibility must be declared on method "add_custom_tax_fields_oncreate_site" Open
function add_custom_tax_fields_oncreate_site() {
- 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_site_url'>" . __( 'web site', 'wpldp' ). '</label></th>';
- Exclude checks
Concat operator must be surrounded by a single space Open
echo "<label for='ldp_site'>" . __( 'web site', 'wpldp' ). '</label>';
- Exclude checks
Expected 2 spaces after parameter type; 1 found Open
* @param \WP_REST_Request $request The current HTTP request object.
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '"<td>
<input type="url" placeholder="http://" name="ldp_site_url" id="ldp_site_url" value="$ldp_site_url">"'.</td> Open
echo "<td><input type='url' placeholder='http://' name='ldp_site_url' id='ldp_site_url' value='$ldp_site_url' />";
- Exclude checks
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space Open
$term = null;
- Exclude checks
No space found after comma in function call Open
$term_meta = get_term_meta( $term_id,'ldp_site_url', true );
- Exclude checks