phplib/Postmortem.php

Summary

Maintainability
F
4 days
Test Coverage

File Postmortem.php has 394 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

require_once('Persistence.php');

/**
Severity: Minor
Found in phplib/Postmortem.php - About 5 hrs to fix

    Method save_tags_for_event has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static function save_tags_for_event($event_id, $tags, $conn = null) {
            $conn = $conn ?: Persistence::get_database_object();
            if (is_null($conn)) {
                return array("status" => self::ERROR,
                    "error" => "Couldn't get connection object.");
    Severity: Minor
    Found in phplib/Postmortem.php - About 1 hr to fix

      Method delete_tag has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static function delete_tag($tag_id, $event_id = null, $conn = null) {
              $conn = $conn ?: Persistence::get_database_object();
              if (is_null($conn)) {
                  return array("status" => self::ERROR,
                      "error" => "Couldn't get connection object.");
      Severity: Minor
      Found in phplib/Postmortem.php - About 1 hr to fix

        Method undelete_tag has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static function undelete_tag($tag_id, $event_id = null, $conn = null) {
                $conn = $conn ?: Persistence::get_database_object();
                if (is_null($conn)) {
                    return array("status" => self::ERROR,
                        "error" => "Couldn't get connection object.");
        Severity: Minor
        Found in phplib/Postmortem.php - About 1 hr to fix

          Method add_history has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              static function add_history($event, $admin, $action, $conn = null) {
                  // validate action
                  if (!in_array($action, array(self::ACTION_ADD, self::ACTION_EDIT))) {
                      return array(
                          "status" => self::ERROR,
          Severity: Minor
          Found in phplib/Postmortem.php - About 1 hr to fix

            Function save_tags_for_event has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                static function save_tags_for_event($event_id, $tags, $conn = null) {
                    $conn = $conn ?: Persistence::get_database_object();
                    if (is_null($conn)) {
                        return array("status" => self::ERROR,
                            "error" => "Couldn't get connection object.");
            Severity: Minor
            Found in phplib/Postmortem.php - About 55 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 delete_tag has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                static function delete_tag($tag_id, $event_id = null, $conn = null) {
                    $conn = $conn ?: Persistence::get_database_object();
                    if (is_null($conn)) {
                        return array("status" => self::ERROR,
                            "error" => "Couldn't get connection object.");
            Severity: Minor
            Found in phplib/Postmortem.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 undelete_tag has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                static function undelete_tag($tag_id, $event_id = null, $conn = null) {
                    $conn = $conn ?: Persistence::get_database_object();
                    if (is_null($conn)) {
                        return array("status" => self::ERROR,
                            "error" => "Couldn't get connection object.");
            Severity: Minor
            Found in phplib/Postmortem.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

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

                static function delete_tag($tag_id, $event_id = null, $conn = null) {
                    $conn = $conn ?: Persistence::get_database_object();
                    if (is_null($conn)) {
                        return array("status" => self::ERROR,
                            "error" => "Couldn't get connection object.");
            Severity: Major
            Found in phplib/Postmortem.php and 1 other location - About 1 day to fix
            phplib/Postmortem.php on lines 483..531

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

            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

                static function undelete_tag($tag_id, $event_id = null, $conn = null) {
                    $conn = $conn ?: Persistence::get_database_object();
                    if (is_null($conn)) {
                        return array("status" => self::ERROR,
                            "error" => "Couldn't get connection object.");
            Severity: Major
            Found in phplib/Postmortem.php and 1 other location - About 1 day to fix
            phplib/Postmortem.php on lines 423..471

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

            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 4 locations. Consider refactoring.
            Open

                static function get_tags_for_event($event_id, $conn = null) {
                    $conn = $conn ?: Persistence::get_database_object();
                    $columns = array('id', 'title');
                    $table_name = 'tags';
                    $where = array(
            Severity: Major
            Found in phplib/Postmortem.php and 3 other locations - About 2 hrs to fix
            features/images/lib.php on lines 19..33
            features/irc/lib.php on lines 36..50
            features/jira/lib.php on lines 19..33

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

            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

            Each class must be in a namespace of at least one level (a top-level vendor name)
            Open

            class Postmortem {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "get_tags"
            Open

                static function get_tags($conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::humanize_history" is not in camel caps format
            Open

                static function humanize_history($history) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "undelete_event"
            Open

                static function undelete_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "get_event_edit_status"
            Open

                static function get_event_edit_status($event) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "get_tags_for_event"
            Open

                static function get_tags_for_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Expected 0 spaces before closing bracket; 1 found
            Open

                            } elseif( $row['deleted'] ) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::delete_tag" is not in camel caps format
            Open

                static function delete_tag($tag_id, $event_id = null, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "get_history"
            Open

                static function get_history($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "delete_event"
            Open

                static function delete_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "set_event_edit_status"
            Open

                static function set_event_edit_status($id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::get_tags" is not in camel caps format
            Open

                static function get_tags($conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "delete_tags_for_event"
            Open

                static function delete_tags_for_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace of a class must be on the line after the definition
            Open

            class Postmortem {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "get_events_for_tags"
            Open

                static function get_events_for_tags($tag_ids, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "get_events_by_date"
            Open

                static function get_events_by_date($start_date = null, $end_date = null, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::get_event" is not in camel caps format
            Open

                static function get_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::delete_event" is not in camel caps format
            Open

                static function delete_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "undelete_tag"
            Open

                static function undelete_tag($tag_id, $event_id = null, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "add_history"
            Open

                static function add_history($event, $admin, $action, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::save_event" is not in camel caps format
            Open

                static function save_event($event, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::undelete_event" is not in camel caps format
            Open

                static function undelete_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::get_events_for_tags" is not in camel caps format
            Open

                static function get_events_for_tags($tag_ids, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "get_history_event"
            Open

                static function get_history_event($id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::get_event_edit_status" is not in camel caps format
            Open

                static function get_event_edit_status($event) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::get_all_events" is not in camel caps format
            Open

                static function get_all_events($conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::delete_tags_for_event" is not in camel caps format
            Open

                static function delete_tags_for_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "save_tags_for_event"
            Open

                static function save_tags_for_event($event_id, $tags, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "get_event"
            Open

                static function get_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::get_severity_levels" is not in camel caps format
            Open

                static function get_severity_levels() {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "save_event"
            Open

                static function save_event($event, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::set_event_edit_status" is not in camel caps format
            Open

                static function set_event_edit_status($id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "get_all_events"
            Open

                static function get_all_events($conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::save_tags_for_event" is not in camel caps format
            Open

                static function save_tags_for_event($event_id, $tags, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "delete_tag"
            Open

                static function delete_tag($tag_id, $event_id = null, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::get_history_event" is not in camel caps format
            Open

                static function get_history_event($id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "humanize_history"
            Open

                static function humanize_history($history) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Visibility must be declared on method "get_severity_levels"
            Open

                static function get_severity_levels() {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::get_tags_for_event" is not in camel caps format
            Open

                static function get_tags_for_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::get_events_by_date" is not in camel caps format
            Open

                static function get_events_by_date($start_date = null, $end_date = null, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Blank line found at end of control structure
            Open

            
            
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::undelete_tag" is not in camel caps format
            Open

                static function undelete_tag($tag_id, $event_id = null, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Blank line found at end of control structure
            Open

            
            
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::add_history" is not in camel caps format
            Open

                static function add_history($event, $admin, $action, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Method name "Postmortem::get_history" is not in camel caps format
            Open

                static function get_history($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function set_event_edit_status($id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function get_history($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Whitespace found at end of line
            Open

                /** 
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function get_events_by_date($start_date = null, $end_date = null, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Expected 1 space after ELSEIF keyword; 0 found
            Open

                            } elseif( $row['deleted'] ) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function delete_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Whitespace found at end of line
            Open

                    if (strcmp($user['username'], $event['modifier']) != 0) {                  
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function get_tags_for_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Whitespace found at end of line
            Open

                 * @returns EDIT_UNLOCKED if editable, EDIT_LOCKED if a user is currently editing, 
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Expected 0 spaces after opening bracket; 1 found
            Open

                            } elseif( $row['deleted'] ) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function get_tags($conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function get_severity_levels() {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function delete_tags_for_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Whitespace found at end of line
            Open

                        return array("status" => self::ERROR, "error" => $e->getMessage()); 
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function get_events_for_tags($tag_ids, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Expected 1 space after CATCH keyword; 0 found
            Open

                    } catch(PDOException $e) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function save_event($event, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function undelete_tag($tag_id, $event_id = null, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function save_tags_for_event($event_id, $tags, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function humanize_history($history) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function undelete_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function get_all_events($conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function get_event($event_id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function get_event_edit_status($event) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function delete_tag($tag_id, $event_id = null, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function get_history_event($id, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Expected 1 space after CATCH keyword; 0 found
            Open

                    } catch(PDOException $e) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            Opening brace should be on a new line
            Open

                static function add_history($event, $admin, $action, $conn = null) {
            Severity: Minor
            Found in phplib/Postmortem.php by phpcodesniffer

            There are no issues that match your filters.

            Category
            Status