wikimedia/mediawiki-core

View on GitHub
includes/changetags/ChangeTags.php

Summary

Maintainability
F
6 days
Test Coverage

File ChangeTags.php has 599 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Recent changes tagging.
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Major
Found in includes/changetags/ChangeTags.php - About 1 day to fix

    ChangeTags has 37 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ChangeTags {
        /**
         * The tagged edit changes the content model of the page.
         */
        public const TAG_CONTENT_MODEL_CHANGE = 'mw-contentmodelchange';
    Severity: Minor
    Found in includes/changetags/ChangeTags.php - About 4 hrs to fix

      Method updateTagsWithChecks has 63 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function updateTagsWithChecks( $tagsToAdd, $tagsToRemove,
              $rc_id, $rev_id, $log_id, $params, string $reason, Authority $performer
          ) {
              if ( !$tagsToAdd && !$tagsToRemove ) {
                  // no-op, don't bother
      Severity: Major
      Found in includes/changetags/ChangeTags.php - About 2 hrs to fix

        Method buildTagFilterSelector has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function buildTagFilterSelector(
                $selected = '', $ooui = false, IContextSource $context = null
            ) {
                if ( !$context ) {
                    $context = RequestContext::getMain();
        Severity: Minor
        Found in includes/changetags/ChangeTags.php - About 1 hr to fix

          Method formatSummaryRow has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function formatSummaryRow( $tags, $unused, MessageLocalizer $localizer = null ) {
                  if ( $tags === '' || $tags === null ) {
                      return [ '', [] ];
                  }
                  if ( !$localizer ) {
          Severity: Minor
          Found in includes/changetags/ChangeTags.php - About 1 hr to fix

            Method canDeleteTag has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function canDeleteTag( $tag, Authority $performer = null, int $flags = 0 ) {
                    $user = null;
                    $services = MediaWikiServices::getInstance();
                    if ( $performer !== null ) {
                        if ( !$performer->isAllowed( 'deletechangetags' ) ) {
            Severity: Minor
            Found in includes/changetags/ChangeTags.php - About 1 hr to fix

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

                  public static function canUpdateTags(
                      array $tagsToAdd,
                      array $tagsToRemove,
                      Authority $performer = null
                  ) {
              Severity: Minor
              Found in includes/changetags/ChangeTags.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 formatSummaryRow has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function formatSummaryRow( $tags, $unused, MessageLocalizer $localizer = null ) {
                      if ( $tags === '' || $tags === null ) {
                          return [ '', [] ];
                      }
                      if ( !$localizer ) {
              Severity: Minor
              Found in includes/changetags/ChangeTags.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 canUpdateTags has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public static function canUpdateTags(
                      array $tagsToAdd,
                      array $tagsToRemove,
                      Authority $performer = null
                  ) {
              Severity: Minor
              Found in includes/changetags/ChangeTags.php - About 1 hr to fix

                Method canCreateTag has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static function canCreateTag( $tag, Authority $performer = null ) {
                        $user = null;
                        $services = MediaWikiServices::getInstance();
                        if ( $performer !== null ) {
                            if ( !$performer->isAllowed( 'managechangetags' ) ) {
                Severity: Minor
                Found in includes/changetags/ChangeTags.php - About 1 hr to fix

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

                      public static function canDeleteTag( $tag, Authority $performer = null, int $flags = 0 ) {
                          $user = null;
                          $services = MediaWikiServices::getInstance();
                          if ( $performer !== null ) {
                              if ( !$performer->isAllowed( 'deletechangetags' ) ) {
                  Severity: Minor
                  Found in includes/changetags/ChangeTags.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 updateTagsWithChecks has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public static function updateTagsWithChecks( $tagsToAdd, $tagsToRemove,
                          $rc_id, $rev_id, $log_id, $params, string $reason, Authority $performer
                      ) {
                          if ( !$tagsToAdd && !$tagsToRemove ) {
                              // no-op, don't bother
                  Severity: Minor
                  Found in includes/changetags/ChangeTags.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 getChangeTagListSummary has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public static function getChangeTagListSummary( MessageLocalizer $localizer, Language $lang ) {
                          $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                          return $cache->getWithSetCallback(
                              $cache->makeKey( 'tags-list-summary', $lang->getCode() ),
                              WANObjectCache::TTL_DAY,
                  Severity: Minor
                  Found in includes/changetags/ChangeTags.php - About 1 hr to fix

                    Method updateTags has 8 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        public static function updateTags( $tagsToAdd, $tagsToRemove, &$rc_id = null,
                            &$rev_id = null, &$log_id = null, $params = null, RecentChange $rc = null,
                            UserIdentity $user = null
                    Severity: Major
                    Found in includes/changetags/ChangeTags.php - About 1 hr to fix

                      Method updateTagsWithChecks has 8 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          public static function updateTagsWithChecks( $tagsToAdd, $tagsToRemove,
                              $rc_id, $rev_id, $log_id, $params, string $reason, Authority $performer
                      Severity: Major
                      Found in includes/changetags/ChangeTags.php - About 1 hr to fix

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

                            public static function canCreateTag( $tag, Authority $performer = null ) {
                                $user = null;
                                $services = MediaWikiServices::getInstance();
                                if ( $performer !== null ) {
                                    if ( !$performer->isAllowed( 'managechangetags' ) ) {
                        Severity: Minor
                        Found in includes/changetags/ChangeTags.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

                        Method modifyDisplayQuery has 7 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            public static function modifyDisplayQuery( &$tables, &$fields, &$conds,
                                &$join_conds, &$options, $filter_tag = '', bool $exclude = false
                        Severity: Major
                        Found in includes/changetags/ChangeTags.php - About 50 mins to fix

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

                              public static function canActivateTag( $tag, Authority $performer = null ) {
                                  if ( $performer !== null ) {
                                      if ( !$performer->isAllowed( 'managechangetags' ) ) {
                                          return Status::newFatal( 'tags-manage-no-permission' );
                                      }
                          Severity: Minor
                          Found in includes/changetags/ChangeTags.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

                          Method addTags has 6 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              public static function addTags( $tags, $rc_id = null, $rev_id = null,
                                  $log_id = null, $params = null, RecentChange $rc = null
                          Severity: Minor
                          Found in includes/changetags/ChangeTags.php - About 45 mins to fix

                            Method deleteTagWithChecks has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                                public static function deleteTagWithChecks( string $tag, string $reason, Authority $performer,
                                    bool $ignoreWarnings = false, array $logEntryTags = []
                            Severity: Minor
                            Found in includes/changetags/ChangeTags.php - About 35 mins to fix

                              Method activateTagWithChecks has 5 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                  public static function activateTagWithChecks( string $tag, string $reason, Authority $performer,
                                      bool $ignoreWarnings = false, array $logEntryTags = []
                              Severity: Minor
                              Found in includes/changetags/ChangeTags.php - About 35 mins to fix

                                Method createTagWithChecks has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                    public static function createTagWithChecks( string $tag, string $reason, Authority $performer,
                                        bool $ignoreWarnings = false, array $logEntryTags = []
                                Severity: Minor
                                Found in includes/changetags/ChangeTags.php - About 35 mins to fix

                                  Method deactivateTagWithChecks has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                      public static function deactivateTagWithChecks( string $tag, string $reason, Authority $performer,
                                          bool $ignoreWarnings = false, array $logEntryTags = []
                                  Severity: Minor
                                  Found in includes/changetags/ChangeTags.php - About 35 mins to fix

                                    Function canAddTagsAccompanyingChange has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        public static function canAddTagsAccompanyingChange(
                                            array $tags,
                                            Authority $performer = null,
                                            $checkBlock = true
                                        ) {
                                    Severity: Minor
                                    Found in includes/changetags/ChangeTags.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 canDeactivateTag has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        public static function canDeactivateTag( $tag, Authority $performer = null ) {
                                            if ( $performer !== null ) {
                                                if ( !$performer->isAllowed( 'managechangetags' ) ) {
                                                    return Status::newFatal( 'tags-manage-no-permission' );
                                                }
                                    Severity: Minor
                                    Found in includes/changetags/ChangeTags.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

                                    Avoid too many return statements within this method.
                                    Open

                                            return Status::newGood();
                                    Severity: Major
                                    Found in includes/changetags/ChangeTags.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                              return Status::newGood( (object)[
                                                  'logId' => $logId,
                                                  'addedTags' => $tagsAdded,
                                                  'removedTags' => $tagsRemoved,
                                              ] );
                                      Severity: Major
                                      Found in includes/changetags/ChangeTags.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                return Status::newGood();
                                        Severity: Major
                                        Found in includes/changetags/ChangeTags.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                  return $status;
                                          Severity: Major
                                          Found in includes/changetags/ChangeTags.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                    return $canCreateResult;
                                            Severity: Major
                                            Found in includes/changetags/ChangeTags.php - About 30 mins to fix

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

                                                  public static function getChangeTagList( MessageLocalizer $localizer, Language $lang ) {
                                                      $tags = self::getChangeTagListSummary( $localizer, $lang );
                                                      foreach ( $tags as &$tagInfo ) {
                                                          if ( $tagInfo['labelMsg'] ) {
                                                              // Use localizer with the correct page title to parse plain message from the cache.
                                              Severity: Minor
                                              Found in includes/changetags/ChangeTags.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 buildTagFilterSelector has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                                  public static function buildTagFilterSelector(
                                                      $selected = '', $ooui = false, IContextSource $context = null
                                                  ) {
                                                      if ( !$context ) {
                                                          $context = RequestContext::getMain();
                                              Severity: Minor
                                              Found in includes/changetags/ChangeTags.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

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

                                                  public static function deactivateTagWithChecks( string $tag, string $reason, Authority $performer,
                                                      bool $ignoreWarnings = false, array $logEntryTags = []
                                                  ) {
                                                      // are we allowed to do this?
                                                      $result = self::canDeactivateTag( $tag, $performer );
                                              Severity: Major
                                              Found in includes/changetags/ChangeTags.php and 2 other locations - About 3 hrs to fix
                                              includes/changetags/ChangeTags.php on lines 811..828
                                              includes/changetags/ChangeTags.php on lines 995..1011

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

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

                                                  public static function activateTagWithChecks( string $tag, string $reason, Authority $performer,
                                                      bool $ignoreWarnings = false, array $logEntryTags = []
                                                  ) {
                                                      // are we allowed to do this?
                                                      $result = self::canActivateTag( $tag, $performer );
                                              Severity: Major
                                              Found in includes/changetags/ChangeTags.php and 2 other locations - About 3 hrs to fix
                                              includes/changetags/ChangeTags.php on lines 877..894
                                              includes/changetags/ChangeTags.php on lines 995..1011

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

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

                                                  public static function createTagWithChecks( string $tag, string $reason, Authority $performer,
                                                      bool $ignoreWarnings = false, array $logEntryTags = []
                                                  ) {
                                                      // are we allowed to do this?
                                                      $result = self::canCreateTag( $tag, $performer );
                                              Severity: Major
                                              Found in includes/changetags/ChangeTags.php and 2 other locations - About 3 hrs to fix
                                              includes/changetags/ChangeTags.php on lines 811..828
                                              includes/changetags/ChangeTags.php on lines 877..894

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

                                              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

                                              There are no issues that match your filters.

                                              Category
                                              Status