wikimedia/mediawiki-core

View on GitHub
includes/content/ContentHandler.php

Summary

Maintainability
F
5 days
Test Coverage

File ContentHandler.php has 650 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * Base class for content handling.
 *
Severity: Major
Found in includes/content/ContentHandler.php - About 1 day to fix

    ContentHandler has 59 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class ContentHandler {
        use ProtectedHookAccessorTrait;
    
        /**
         * Convenience function for getting flat text from a Content object. This
    Severity: Major
    Found in includes/content/ContentHandler.php - About 1 day to fix

      Function getAutoDeleteReason has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getAutoDeleteReason( Title $title, &$hasHistory = false ) {
              if ( func_num_args() === 2 ) {
                  wfDeprecated( __METHOD__ . ': $hasHistory parameter', '1.38' );
              }
              $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
      Severity: Minor
      Found in includes/content/ContentHandler.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 getAutoDeleteReason has 63 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getAutoDeleteReason( Title $title, &$hasHistory = false ) {
              if ( func_num_args() === 2 ) {
                  wfDeprecated( __METHOD__ . ': $hasHistory parameter', '1.38' );
              }
              $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
      Severity: Major
      Found in includes/content/ContentHandler.php - About 2 hrs to fix

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

            public function getAutosummary(
                Content $oldContent = null,
                Content $newContent = null,
                $flags = 0
            ) {
        Severity: Major
        Found in includes/content/ContentHandler.php - About 2 hrs to fix

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

              private function getChangeType(
                  Content $oldContent = null,
                  Content $newContent = null,
                  $flags = 0
              ) {
          Severity: Minor
          Found in includes/content/ContentHandler.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 getParserOutput has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getParserOutput(
                  Content $content,
                  ContentParseParams $cpoParams
              ) {
                  $services = MediaWikiServices::getInstance();
          Severity: Minor
          Found in includes/content/ContentHandler.php - About 1 hr to fix

            Method createTextSlotDiffRenderer has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                final protected function createTextSlotDiffRenderer( array $options = [] ): TextSlotDiffRenderer {
                    $slotDiffRenderer = new TextSlotDiffRenderer();
            
                    $services = MediaWikiServices::getInstance();
                    $statsdDataFactory = $services->getStatsdDataFactory();
            Severity: Minor
            Found in includes/content/ContentHandler.php - About 1 hr to fix

              Method getChangeType has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function getChangeType(
                      Content $oldContent = null,
                      Content $newContent = null,
                      $flags = 0
                  ) {
              Severity: Minor
              Found in includes/content/ContentHandler.php - About 1 hr to fix

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

                    public function getDataForSearchIndex(
                        WikiPage $page,
                        ParserOutput $output,
                        SearchEngine $engine,
                        RevisionRecord $revision = null
                Severity: Minor
                Found in includes/content/ContentHandler.php - About 1 hr to fix

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

                      public function createDifferenceEngine( IContextSource $context, $old = 0, $new = 0,
                          $rcid = 0, // FIXME: Deprecated, no longer used
                          $refreshCache = false, $unhide = false
                  Severity: Minor
                  Found in includes/content/ContentHandler.php - About 45 mins to fix

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

                        final protected function createTextSlotDiffRenderer( array $options = [] ): TextSlotDiffRenderer {
                            $slotDiffRenderer = new TextSlotDiffRenderer();
                    
                            $services = MediaWikiServices::getInstance();
                            $statsdDataFactory = $services->getStatsdDataFactory();
                    Severity: Minor
                    Found in includes/content/ContentHandler.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 wfMessage( 'autosumm-replace' )->rawParams( $truncatedtext )
                                        ->inContentLanguage()->text();
                    Severity: Major
                    Found in includes/content/ContentHandler.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return 'newblank';
                      Severity: Major
                      Found in includes/content/ContentHandler.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        return 'newpage';
                        Severity: Major
                        Found in includes/content/ContentHandler.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return wfMessage( 'autosumm-new' )->rawParams( $truncatedtext )
                                              ->inContentLanguage()->text();
                          Severity: Major
                          Found in includes/content/ContentHandler.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return wfMessage( 'autosumm-blank' )->inContentLanguage()->text();
                            Severity: Major
                            Found in includes/content/ContentHandler.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return wfMessage( 'autosumm-newblank' )->inContentLanguage()->text();
                              Severity: Major
                              Found in includes/content/ContentHandler.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return 'replace';
                                Severity: Major
                                Found in includes/content/ContentHandler.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return null;
                                  Severity: Major
                                  Found in includes/content/ContentHandler.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                    return '';
                                    Severity: Major
                                    Found in includes/content/ContentHandler.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                  return 'contentmodelchange';
                                      Severity: Major
                                      Found in includes/content/ContentHandler.php - About 30 mins to fix

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

                                                    case 'new-redirect':
                                                        $newTarget = $newContent->getRedirectTarget();
                                                        $truncatedtext = $newContent->getTextForSummary(
                                                            $summaryLimit
                                                            - strlen( wfMessage( 'autoredircomment' )->inContentLanguage()->text() )
                                        Severity: Minor
                                        Found in includes/content/ContentHandler.php and 1 other location - About 40 mins to fix
                                        includes/content/ContentHandler.php on lines 960..969

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

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

                                                    case 'removed-redirect':
                                                        $oldTarget = $oldContent->getRedirectTarget();
                                                        $truncatedtext = $newContent->getTextForSummary(
                                                            $summaryLimit
                                                            - strlen( wfMessage( 'autosumm-removed-redirect' )
                                        Severity: Minor
                                        Found in includes/content/ContentHandler.php and 1 other location - About 40 mins to fix
                                        includes/content/ContentHandler.php on lines 934..943

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

                                        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