wikimedia/mediawiki-core

View on GitHub
includes/Message/Message.php

Summary

Maintainability
F
5 days
Test Coverage

File Message.php has 663 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
Severity: Major
Found in includes/Message/Message.php - About 1 day to fix

    Message has 69 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Message implements MessageSpecifier, Serializable {
        /** Use message text as-is */
        public const FORMAT_PLAIN = 'plain';
        /** Use normal wikitext -> HTML parsing (the result will be wrapped in a block-level HTML tag) */
        public const FORMAT_BLOCK_PARSE = 'block-parse';
    Severity: Major
    Found in includes/Message/Message.php - About 1 day to fix

      Function extractParam has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function extractParam( $param, $format ) {
              if ( is_array( $param ) ) {
                  if ( isset( $param['raw'] ) ) {
                      return [ 'after', $param['raw'] ];
                  } elseif ( isset( $param['num'] ) ) {
      Severity: Minor
      Found in includes/Message/Message.php - About 4 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 extractParam has 64 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function extractParam( $param, $format ) {
              if ( is_array( $param ) ) {
                  if ( isset( $param['raw'] ) ) {
                      return [ 'after', $param['raw'] ];
                  } elseif ( isset( $param['num'] ) ) {
      Severity: Major
      Found in includes/Message/Message.php - About 2 hrs to fix

        Function format has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            private function format( string $format ): string {
                $string = $this->fetchMessage();
        
                if ( $string === false ) {
                    // Err on the side of safety, ensure that the output
        Severity: Minor
        Found in includes/Message/Message.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 params has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            public function params( ...$args ) {
                // If $args has only one entry and it's an array, then it's either a
                // non-varargs call or it happens to be a call with just a single
                // "special" parameter. Since the "special" parameters don't have any
                // numeric keys, we'll test that to differentiate the cases.
        Severity: Minor
        Found in includes/Message/Message.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 format has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function format( string $format ): string {
                $string = $this->fetchMessage();
        
                if ( $string === false ) {
                    // Err on the side of safety, ensure that the output
        Severity: Minor
        Found in includes/Message/Message.php - About 1 hr to fix

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

              protected function formatListParam( array $params, $listType, $format ) {
                  if ( !isset( self::$listTypeMap[$listType] ) ) {
                      $warning = 'Invalid list type for message "' . $this->getKey() . '": '
                          . htmlspecialchars( $listType )
                          . ' (params are ' . htmlspecialchars( serialize( $params ) ) . ')';
          Severity: Minor
          Found in includes/Message/Message.php - About 1 hr to fix

            Function fetchMessage has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function fetchMessage() {
                    if ( $this->message === null ) {
                        $cache = MediaWikiServices::getInstance()->getMessageCache();
            
                        foreach ( $this->keysToTry as $key ) {
            Severity: Minor
            Found in includes/Message/Message.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 replaceParameters has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function replaceParameters( $message, $type, $format ) {
                    // A temporary marker for $1 parameters that is only valid
                    // in non-attribute contexts. However if the entire message is escaped
                    // then we don't want to use it because it will be mangled in all contexts
                    // and its unnecessary as ->escaped() messages aren't html.
            Severity: Minor
            Found in includes/Message/Message.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 __construct has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                public function __construct( $key, $params = [], Language $language = null ) {
                    if ( $key instanceof MessageSpecifier ) {
                        if ( $params ) {
                            throw new InvalidArgumentException(
                                '$params must be empty if $key is a MessageSpecifier'
            Severity: Minor
            Found in includes/Message/Message.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 inLanguage has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                public function inLanguage( $lang ) {
                    $previousLanguage = $this->language;
            
                    if ( $lang instanceof Language ) {
                        $this->language = $lang;
            Severity: Minor
            Found in includes/Message/Message.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

            Avoid too many return statements within this method.
            Open

                                return [ 'before', $obj->__toString() ];
            Severity: Major
            Found in includes/Message/Message.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                              return [ 'before', $this->getLanguage()->time( $param['time'] ) ];
              Severity: Major
              Found in includes/Message/Message.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return [ 'before', $this->getLanguage()->getGroupName( $param['group'] ) ];
                Severity: Major
                Found in includes/Message/Message.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return [ 'before', $param ];
                  Severity: Major
                  Found in includes/Message/Message.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                        return [
                                            'before',
                                            $this->getLanguage()->getGroupMemberName( $obj->getGroup(), $obj->getMember() )
                                        ];
                    Severity: Major
                    Found in includes/Message/Message.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return [ 'after', $this->formatPlaintext( $param['plaintext'], $format ) ];
                      Severity: Major
                      Found in includes/Message/Message.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        return [ 'before', $this->getLanguage()->timeanddate( $param['datetime'] ) ];
                        Severity: Major
                        Found in includes/Message/Message.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return $this->formatListParam( $param['list'], $param['type'], $format );
                          Severity: Major
                          Found in includes/Message/Message.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return [ 'before', $this->getLanguage()->formatTimePeriod( $param['period'] ) ];
                            Severity: Major
                            Found in includes/Message/Message.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return [ 'before', '[INVALID]' ];
                              Severity: Major
                              Found in includes/Message/Message.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return [ 'after', $msg->format( $format ) ];
                                Severity: Major
                                Found in includes/Message/Message.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                  return [ 'before', $this->getLanguage()->date( $param['date'] ) ];
                                  Severity: Major
                                  Found in includes/Message/Message.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                    return [ 'before', $this->getLanguage()->formatSize( $param['size'] ) ];
                                    Severity: Major
                                    Found in includes/Message/Message.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                      return [ 'before', $this->getLanguage()->formatBitrate( $param['bitrate'] ) ];
                                      Severity: Major
                                      Found in includes/Message/Message.php - About 30 mins to fix

                                        There are no issues that match your filters.

                                        Category
                                        Status