isotopsweden/wp-cargo

View on GitHub
src/admin/options.php

Summary

Maintainability
B
5 hrs
Test Coverage

push_options accesses the super-global variable $_POST.
Open

function push_options() {
    if ( empty( $_POST ) ) {
        return false;
    }

Severity: Minor
Found in src/admin/options.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Reduce the number of returns of this function 4, down to the maximum allowed 3.
Open

function push_options() {
Severity: Major
Found in src/admin/options.php by sonar-php

Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

Noncompliant Code Example

With the default threshold of 3:

function myFunction(){ // Noncompliant as there are 4 return statements
  if (condition1) {
    return true;
  } else {
    if (condition2) {
      return false;
    } else {
      return true;
    }
  }
  return false;
}

Define a constant instead of duplicating this literal "\push_options" 4 times.
Open

cargo()->action( 'wp_after_admin_bar_render', __NAMESPACE__ . '\\push_options' );
Severity: Critical
Found in src/admin/options.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Similar blocks of code found in 2 locations. Consider refactoring.
Open

<?php

namespace Isotop\Cargo\Admin;

use Isotop\Cargo\Content\Options;
Severity: Major
Found in src/admin/options.php and 1 other location - About 5 hrs to fix
src/admin/menus.php on lines 1..38

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 184.

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

Further Reading

A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 12 and the first side effect is on line 35.
Open

<?php
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    if ( empty( $_POST ) ) {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    if ( ! is_admin() ) {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    if ( is_wp_error( $res ) ) {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        return false;
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    }
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    // Send options to pusher.
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    // Handle error.
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    $res = cargo()->make( 'pusher' )->send( $data );
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        return false;
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    if ( is_wp_error( $res ) ) {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    return $res;
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        return false;
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    if ( ! is_admin() ) {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    // Create options content object.
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    }
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    $data = new Options();
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    }
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    if ( empty( $_POST ) ) {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces after opening bracket; 1 found
Open

    if ( empty( $_POST ) ) {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

cargo()->action( 'created_term', __NAMESPACE__ . '\\push_options', 999 );
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    if ( empty( $_POST ) ) {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

cargo()->action( 'wp_after_admin_bar_render', __NAMESPACE__ . '\\push_options' );
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

    $res = cargo()->make( 'pusher' )->send( $data );
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

cargo()->action( 'save_post', __NAMESPACE__ . '\\push_options', 999 );
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

cargo()->action( 'edit_term', __NAMESPACE__ . '\\push_options', 999 );
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

cargo()->action( 'created_term', __NAMESPACE__ . '\\push_options', 999 );
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

cargo()->action( 'edit_term', __NAMESPACE__ . '\\push_options', 999 );
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    $res = cargo()->make( 'pusher' )->send( $data );
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces after opening bracket; 1 found
Open

    if ( is_wp_error( $res ) ) {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

cargo()->action( 'save_post', __NAMESPACE__ . '\\push_options', 999 );
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces after opening bracket; 1 found
Open

    if ( ! is_admin() ) {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

    if ( is_wp_error( $res ) ) {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    if ( is_wp_error( $res ) ) {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

    if ( empty( $_POST ) ) {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Opening brace should be on a new line
Open

function push_options() {
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

cargo()->action( 'wp_after_admin_bar_render', __NAMESPACE__ . '\\push_options' );
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Space after opening parenthesis of function call prohibited
Open

    $res = cargo()->make( 'pusher' )->send( $data );
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

Expected 0 spaces before closing bracket; 1 found
Open

    $res = cargo()->make( 'pusher' )->send( $data );
Severity: Minor
Found in src/admin/options.php by phpcodesniffer

There are no issues that match your filters.

Category
Status