wikimedia/mediawiki-core

View on GitHub
includes/CommentStore/CommentStore.php

Summary

Maintainability
C
1 day
Test Coverage

Function getCommentInternal has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

    private function getCommentInternal( ?IReadableDatabase $db, $key, $row, $fallback = false ) {
        $row = (array)$row;
        if ( array_key_exists( "{$key}_text", $row ) && array_key_exists( "{$key}_data", $row ) ) {
            $cid = $row["{$key}_cid"] ?? null;
            $text = $row["{$key}_text"];
Severity: Minor
Found in includes/CommentStore/CommentStore.php - About 5 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 getCommentInternal has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function getCommentInternal( ?IReadableDatabase $db, $key, $row, $fallback = false ) {
        $row = (array)$row;
        if ( array_key_exists( "{$key}_text", $row ) && array_key_exists( "{$key}_data", $row ) ) {
            $cid = $row["{$key}_cid"] ?? null;
            $text = $row["{$key}_text"];
Severity: Major
Found in includes/CommentStore/CommentStore.php - About 2 hrs to fix

    Method createComment has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function createComment( IDatabase $dbw, $comment, array $data = null ) {
            $comment = CommentStoreComment::newUnsavedComment( $comment, $data );
    
            # Truncate comment in a Unicode-sensitive manner
            $comment->text = $this->lang->truncateForVisual( $comment->text, self::COMMENT_CHARACTER_LIMIT );
    Severity: Minor
    Found in includes/CommentStore/CommentStore.php - About 1 hr to fix

      Function createComment has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          public function createComment( IDatabase $dbw, $comment, array $data = null ) {
              $comment = CommentStoreComment::newUnsavedComment( $comment, $data );
      
              # Truncate comment in a Unicode-sensitive manner
              $comment->text = $this->lang->truncateForVisual( $comment->text, self::COMMENT_CHARACTER_LIMIT );
      Severity: Minor
      Found in includes/CommentStore/CommentStore.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 decodeMessage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          private static function decodeMessage( $data ) {
              $key = array_shift( $data );
              foreach ( $data as &$param ) {
                  if ( is_object( $param ) ) {
                      $param = (array)$param;
      Severity: Minor
      Found in includes/CommentStore/CommentStore.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