classes/class-alerts.php

Summary

Maintainability
F
4 days
Test Coverage
B
80%

File class-alerts.php has 584 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Alerts feature class.
 *
 * @package WP_Stream
Severity: Major
Found in classes/class-alerts.php - About 1 day to fix

    Method __construct has 60 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function __construct( $plugin ) {
            $this->plugin = $plugin;
    
            // Register custom post type.
            add_action( 'init', array( $this, 'register_post_type' ) );
    Severity: Major
    Found in classes/class-alerts.php - About 2 hrs to fix

      Method save_new_alert has 60 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function save_new_alert() {
              check_ajax_referer( 'save_alert', 'wp_stream_alerts_nonce' );
      
              if ( ! current_user_can( $this->plugin->admin->settings_cap ) ) {
                  wp_die(
      Severity: Major
      Found in classes/class-alerts.php - About 2 hrs to fix

        Alerts has 21 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class Alerts {
        
            /**
             * Alerts post type slug
             */
        Severity: Minor
        Found in classes/class-alerts.php - About 2 hrs to fix

          Method register_post_type has 54 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function register_post_type() {
                  $labels = array(
                      'name'               => _x( 'Alerts', 'post type general name', 'stream' ),
                      'singular_name'      => _x( 'Alert', 'post type singular name', 'stream' ),
                      'menu_name'          => _x( 'Alerts', 'admin menu', 'stream' ),
          Severity: Major
          Found in classes/class-alerts.php - About 2 hrs to fix

            Method display_submit_box has 48 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function display_submit_box( $post ) {
                    if ( empty( $post ) ) {
                        return;
                    }
            
            
            Severity: Minor
            Found in classes/class-alerts.php - About 1 hr to fix

              Function load_alert_triggers has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function load_alert_triggers() {
                      $alert_triggers = array(
                          'author',
                          'context',
                          'action',
              Severity: Minor
              Found in classes/class-alerts.php - About 1 hr to fix

              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 load_alert_types has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function load_alert_types() {
                      $alert_types = array(
                          'none',
                          'highlight',
                          'email',
              Severity: Minor
              Found in classes/class-alerts.php - About 1 hr to fix

              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 load_alerts_settings has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function load_alerts_settings() {
                      if ( ! current_user_can( self::CAPABILITY ) ) {
                          wp_send_json_error(
                              array(
                                  'message' => 'You do not have permission to do this.',
              Severity: Minor
              Found in classes/class-alerts.php - About 1 hr to fix

                Method load_alert_types has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function load_alert_types() {
                        $alert_types = array(
                            'none',
                            'highlight',
                            'email',
                Severity: Minor
                Found in classes/class-alerts.php - About 1 hr to fix

                  Method display_notification_box has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function display_notification_box( $post = array() ) {
                          $alert      = null;
                          $alert_type = 'none';
                          if ( is_object( $post ) ) {
                              $alert = $this->get_alert( $post->ID );
                  Severity: Minor
                  Found in classes/class-alerts.php - About 1 hr to fix

                    Method load_alert_triggers has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function load_alert_triggers() {
                            $alert_triggers = array(
                                'author',
                                'context',
                                'action',
                    Severity: Minor
                    Found in classes/class-alerts.php - About 1 hr to fix

                      Function save_new_alert has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function save_new_alert() {
                              check_ajax_referer( 'save_alert', 'wp_stream_alerts_nonce' );
                      
                              if ( ! current_user_can( $this->plugin->admin->settings_cap ) ) {
                                  wp_die(
                      Severity: Minor
                      Found in classes/class-alerts.php - About 35 mins to fix

                      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 get_actions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function get_actions() {
                              $connector_name    = wp_stream_filter_input( INPUT_POST, 'connector' );
                              $stream_connectors = wp_stream_get_instance()->connectors;
                              if ( ! empty( $connector_name ) ) {
                                  if ( isset( $stream_connectors->connectors[ $connector_name ] ) ) {
                      Severity: Minor
                      Found in classes/class-alerts.php - About 35 mins to fix

                      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 change_menu_link_url has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function change_menu_link_url() {
                              global $submenu;
                      
                              $parent = 'wp_stream';
                              $page   = 'edit.php?post_type=wp_stream_alerts';
                      Severity: Minor
                      Found in classes/class-alerts.php - About 35 mins to fix

                      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 load_alerts_settings has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function load_alerts_settings() {
                              if ( ! current_user_can( self::CAPABILITY ) ) {
                                  wp_send_json_error(
                                      array(
                                          'message' => 'You do not have permission to do this.',
                      Severity: Minor
                      Found in classes/class-alerts.php - About 25 mins to fix

                      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 display_submit_box has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function display_submit_box( $post ) {
                              if ( empty( $post ) ) {
                                  return;
                              }
                      
                      
                      Severity: Minor
                      Found in classes/class-alerts.php - About 25 mins to fix

                      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 check_records has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function check_records( $record_id, $recordarr ) {
                              $args = array(
                                  'post_type'   => self::POST_TYPE,
                                  'post_status' => 'wp_stream_enabled',
                              );
                      Severity: Minor
                      Found in classes/class-alerts.php - About 25 mins to fix

                      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

                              foreach ( $alert_triggers as $alert_trigger ) {
                                  $file_location = $this->plugin->locations['dir'] . '/alerts/class-alert-trigger-' . $alert_trigger . '.php';
                                  if ( file_exists( $file_location ) ) {
                                      include_once $file_location;
                                      $class_name = sprintf( '\WP_Stream\Alert_Trigger_%s', str_replace( '-', '_', $alert_trigger ) );
                      Severity: Major
                      Found in classes/class-alerts.php and 1 other location - About 2 hrs to fix
                      classes/class-alerts.php on lines 155..169

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

                      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

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

                              foreach ( $alert_types as $alert_type ) {
                                  $file_location = $this->plugin->locations['dir'] . '/alerts/class-alert-type-' . $alert_type . '.php';
                                  if ( file_exists( $file_location ) ) {
                                      include_once $file_location;
                                      $class_name = sprintf( '\WP_Stream\Alert_Type_%s', str_replace( '-', '_', $alert_type ) );
                      Severity: Major
                      Found in classes/class-alerts.php and 1 other location - About 2 hrs to fix
                      classes/class-alerts.php on lines 199..213

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

                      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

                      There are no issues that match your filters.

                      Category
                      Status