wikimedia/mediawiki-core

View on GitHub
includes/logging/LogFormatter.php

Summary

Maintainability
F
5 days
Test Coverage

File LogFormatter.php has 592 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Contains a class for formatting log entries
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Major
Found in includes/logging/LogFormatter.php - About 1 day to fix

    Function getIRCActionText has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getIRCActionText() {
            $this->plaintext = true;
            $this->irctext = true;
    
            $entry = $this->entry;
    Severity: Minor
    Found in includes/logging/LogFormatter.php - About 7 hrs 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 getIRCActionText has 182 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getIRCActionText() {
            $this->plaintext = true;
            $this->irctext = true;
    
            $entry = $this->entry;
    Severity: Major
    Found in includes/logging/LogFormatter.php - About 7 hrs to fix

      LogFormatter has 38 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class LogFormatter {
          // Audience options for viewing usernames, comments, and actions
          public const FOR_PUBLIC = 1;
          public const FOR_THIS_USER = 2;
      
      
      Severity: Minor
      Found in includes/logging/LogFormatter.php - About 5 hrs to fix

        Method formatParameterValueForApi has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function formatParameterValueForApi( $name, $type, $value ) {
                $type = strtolower( trim( $type ) );
                switch ( $type ) {
                    case 'bool':
                        $value = (bool)$value;
        Severity: Major
        Found in includes/logging/LogFormatter.php - About 2 hrs to fix

          Function extractParameters has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function extractParameters() {
                  $entry = $this->entry;
                  $params = [];
          
                  if ( $entry->isLegacy() ) {
          Severity: Minor
          Found in includes/logging/LogFormatter.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 formatParameterValueForApi has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function formatParameterValueForApi( $name, $type, $value ) {
                  $type = strtolower( trim( $type ) );
                  switch ( $type ) {
                      case 'bool':
                          $value = (bool)$value;
          Severity: Minor
          Found in includes/logging/LogFormatter.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 formatParameterValue has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function formatParameterValue( $type, $value ) {
                  $saveLinkFlood = $this->linkFlood;
          
                  switch ( strtolower( trim( $type ) ) ) {
                      case 'raw':
          Severity: Minor
          Found in includes/logging/LogFormatter.php - About 1 hr to fix

            Function formatParameterValue has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function formatParameterValue( $type, $value ) {
                    $saveLinkFlood = $this->linkFlood;
            
                    switch ( strtolower( trim( $type ) ) ) {
                        case 'raw':
            Severity: Minor
            Found in includes/logging/LogFormatter.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 formatParametersForApi has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                public function formatParametersForApi() {
                    $logParams = [];
                    foreach ( $this->getParametersForApi() as $key => $value ) {
                        $vals = explode( ':', $key, 3 );
                        if ( count( $vals ) !== 3 ) {
            Severity: Minor
            Found in includes/logging/LogFormatter.php - About 45 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 getActionText has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getActionText() {
                    if ( $this->canView( LogPage::DELETED_ACTION ) ) {
                        $element = $this->getActionMessage();
                        if ( $element instanceof Message ) {
                            $element = $this->plaintext ? $element->text() : $element->escaped();
            Severity: Minor
            Found in includes/logging/LogFormatter.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 makePageLink has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function makePageLink( Title $title = null, $parameters = [], $html = null ) {
                    if ( !$title instanceof Title ) {
                        $msg = $this->msg( 'invalidtitle' )->text();
                        if ( $this->plaintext ) {
                            return $msg;
            Severity: Minor
            Found in includes/logging/LogFormatter.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

            There are no issues that match your filters.

            Category
            Status