wikimedia/mediawiki-core

View on GitHub
includes/changes/RecentChange.php

Summary

Maintainability
F
1 wk
Test Coverage

File RecentChange.php has 848 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Utility class for creating and accessing recent change entries.
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Major
Found in includes/changes/RecentChange.php - About 2 days to fix

    RecentChange has 36 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class RecentChange implements Taggable {
        use DeprecationHelper;
    
        // Constants for the rc_source field.  Extensions may also have
        // their own source constants.
    Severity: Minor
    Found in includes/changes/RecentChange.php - About 4 hrs to fix

      Method save has 109 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function save( $send = self::SEND_FEED ) {
              $services = MediaWikiServices::getInstance();
              $mainConfig = $services->getMainConfig();
              $putIPinRC = $mainConfig->get( MainConfigNames::PutIPinRC );
              $dbw = $services->getConnectionProvider()->getPrimaryDatabase();
      Severity: Major
      Found in includes/changes/RecentChange.php - About 4 hrs to fix

        Method newLogEntry has 76 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function newLogEntry( $timestamp,
                $logPage, $user, $actionComment, $ip,
                $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '',
                $revId = 0, $isPatrollable = false, $forceBotFlag = null
            ) {
        Severity: Major
        Found in includes/changes/RecentChange.php - About 3 hrs to fix

          Consider simplifying this complex logical expression.
          Open

                      if (
                          ( $params['omit_bots'] && $this->mAttribs['rc_bot'] ) ||
                          ( $params['omit_anon'] && !$performer->isRegistered() ) ||
                          ( $params['omit_user'] && $performer->isRegistered() ) ||
                          ( $params['omit_minor'] && $this->mAttribs['rc_minor'] ) ||
          Severity: Critical
          Found in includes/changes/RecentChange.php - About 2 hrs to fix

            Function getUserIdentityFromAnyId has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

                private function getUserIdentityFromAnyId(
                    $userId,
                    $userName,
                    $actorId = null
                ): UserIdentity {
            Severity: Minor
            Found in includes/changes/RecentChange.php - About 2 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 newForCategorization has 51 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function newForCategorization(
                    $timestamp,
                    PageIdentity $categoryTitle,
                    ?UserIdentity $user,
                    $comment,
            Severity: Major
            Found in includes/changes/RecentChange.php - About 2 hrs to fix

              Method notifyEdit has 49 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public static function notifyEdit(
                      $timestamp, $page, $minor, $user, $comment, $oldId, $lastTimestamp,
                      $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0,
                      $tags = [], EditResult $editResult = null
                  ) {
              Severity: Minor
              Found in includes/changes/RecentChange.php - About 1 hr to fix

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

                    public static function notifyNew(
                        $timestamp,
                        $page, $minor, $user, $comment, $bot,
                        $ip = '', $size = 0, $newId = 0, $patrol = 0, $tags = []
                    ) {
                Severity: Minor
                Found in includes/changes/RecentChange.php - About 1 hr to fix

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

                      public function save( $send = self::SEND_FEED ) {
                          $services = MediaWikiServices::getInstance();
                          $mainConfig = $services->getMainConfig();
                          $putIPinRC = $mainConfig->get( MainConfigNames::PutIPinRC );
                          $dbw = $services->getConnectionProvider()->getPrimaryDatabase();
                  Severity: Minor
                  Found in includes/changes/RecentChange.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 doMarkPatrolled has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function doMarkPatrolled( Authority $performer, $auto = null, $tags = null ) {
                          if ( $auto ) {
                              wfWarn( __METHOD__ . ' with $auto = true' );
                              return [];
                          }
                  Severity: Minor
                  Found in includes/changes/RecentChange.php - About 1 hr to fix

                    Method notifyEdit has 15 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                            $timestamp, $page, $minor, $user, $comment, $oldId, $lastTimestamp,
                            $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0,
                            $tags = [], EditResult $editResult = null
                    Severity: Major
                    Found in includes/changes/RecentChange.php - About 1 hr to fix

                      Method newLogEntry has 15 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          public static function newLogEntry( $timestamp,
                              $logPage, $user, $actionComment, $ip,
                              $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '',
                              $revId = 0, $isPatrollable = false, $forceBotFlag = null
                      Severity: Major
                      Found in includes/changes/RecentChange.php - About 1 hr to fix

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

                            public function doMarkPatrolled( Authority $performer, $auto = null, $tags = null ) {
                                if ( $auto ) {
                                    wfWarn( __METHOD__ . ' with $auto = true' );
                                    return [];
                                }
                        Severity: Minor
                        Found in includes/changes/RecentChange.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 notifyRCFeeds has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function notifyRCFeeds( array $feeds = null ) {
                                $feeds ??=
                                    MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::RCFeeds );
                        
                                $performer = $this->getPerformerIdentity();
                        Severity: Minor
                        Found in includes/changes/RecentChange.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 notifyLog has 12 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            public static function notifyLog( $timestamp,
                                $logPage, $user, $actionComment, $ip, $type,
                                $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = ''
                        Severity: Major
                        Found in includes/changes/RecentChange.php - About 1 hr to fix

                          Method newForCategorization has 12 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                                  $timestamp,
                                  PageIdentity $categoryTitle,
                                  ?UserIdentity $user,
                                  $comment,
                                  PageIdentity $pageTitle,
                          Severity: Major
                          Found in includes/changes/RecentChange.php - About 1 hr to fix

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

                                public static function getQueryInfo() {
                                    $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin( 'rc_comment' );
                                    // Optimizer sometimes refuses to pick up the correct join order (T311360)
                                    $commentQuery['joins']['comment_rc_comment'][0] = 'STRAIGHT_JOIN';
                                    return [
                            Severity: Minor
                            Found in includes/changes/RecentChange.php - About 1 hr to fix

                              Method notifyNew has 11 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                      $timestamp,
                                      $page, $minor, $user, $comment, $bot,
                                      $ip = '', $size = 0, $newId = 0, $patrol = 0, $tags = []
                              Severity: Major
                              Found in includes/changes/RecentChange.php - About 1 hr to fix

                                Function newLogEntry has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public static function newLogEntry( $timestamp,
                                        $logPage, $user, $actionComment, $ip,
                                        $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '',
                                        $revId = 0, $isPatrollable = false, $forceBotFlag = null
                                    ) {
                                Severity: Minor
                                Found in includes/changes/RecentChange.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 getUserIdentityFromAnyId has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    private function getUserIdentityFromAnyId(
                                        $userId,
                                        $userName,
                                        $actorId = null
                                    ): UserIdentity {
                                Severity: Minor
                                Found in includes/changes/RecentChange.php - About 1 hr to fix

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

                                      public function getNotifyUrl() {
                                          $services = MediaWikiServices::getInstance();
                                          $mainConfig = $services->getMainConfig();
                                          $useRCPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol );
                                          $useNPPatrol = $mainConfig->get( MainConfigNames::UseNPPatrol );
                                  Severity: Minor
                                  Found in includes/changes/RecentChange.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 getAttribute has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      public function getAttribute( $name ) {
                                          if ( $name === 'rc_comment' ) {
                                              return MediaWikiServices::getInstance()->getCommentStore()
                                                  ->getComment( 'rc_comment', $this->mAttribs, true )->text;
                                          }
                                  Severity: Minor
                                  Found in includes/changes/RecentChange.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

                                  Consider simplifying this complex logical expression.
                                  Open

                                          if ( !$useRCPatrol && ( !$useNPPatrol || $this->getAttribute( 'rc_type' ) != RC_NEW ) &&
                                              ( !$useFilePatrol || !( $this->getAttribute( 'rc_type' ) == RC_LOG &&
                                              $this->getAttribute( 'rc_log_type' ) == 'upload' ) ) ) {
                                              $status->fatal( 'rcpatroldisabled' );
                                          }
                                  Severity: Major
                                  Found in includes/changes/RecentChange.php - About 40 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                            return $this->mAttribs[$name] ?? null;
                                    Severity: Major
                                    Found in includes/changes/RecentChange.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                              return [];
                                      Severity: Major
                                      Found in includes/changes/RecentChange.php - About 30 mins to fix

                                        Function checkIPAddress has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                        Open

                                            private static function checkIPAddress( $ip ) {
                                                global $wgRequest;
                                        
                                                if ( $ip ) {
                                                    if ( !IPUtils::isIPAddress( $ip ) ) {
                                        Severity: Minor
                                        Found in includes/changes/RecentChange.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