wikimedia/mediawiki-core

View on GitHub
includes/diff/DifferenceEngine.php

Summary

Maintainability
F
1 wk
Test Coverage

File DifferenceEngine.php has 1431 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * User interface for the difference engine.
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Major
Found in includes/diff/DifferenceEngine.php - About 3 days to fix

    Method showDiffPage has 260 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function showDiffPage( $diffOnly = false ) {
            # Allow frames except in certain special cases
            $out = $this->getOutput();
            $out->setPreventClickjacking( false );
            $out->setRobotPolicy( 'noindex,nofollow' );
    Severity: Major
    Found in includes/diff/DifferenceEngine.php - About 1 day to fix

      DifferenceEngine has 68 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class DifferenceEngine extends ContextSource {
      
          use DeprecationHelper;
      
          /**
      Severity: Major
      Found in includes/diff/DifferenceEngine.php - About 1 day to fix

        Function showDiffPage has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
        Open

            public function showDiffPage( $diffOnly = false ) {
                # Allow frames except in certain special cases
                $out = $this->getOutput();
                $out->setPreventClickjacking( false );
                $out->setRobotPolicy( 'noindex,nofollow' );
        Severity: Minor
        Found in includes/diff/DifferenceEngine.php - About 1 day 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 getDiffBody has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
        Open

            public function getDiffBody() {
                $this->mCacheHit = true;
                // Check if the diff should be hidden from this user
                if ( !$this->isContentOverridden ) {
                    if ( !$this->loadRevisionData() ) {
        Severity: Minor
        Found in includes/diff/DifferenceEngine.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

        Function loadRevisionData has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

            public function loadRevisionData() {
                if ( $this->mRevisionsLoaded ) {
                    return $this->isContentOverridden ||
                    ( $this->mOldRevisionRecord !== null && $this->mNewRevisionRecord !== null );
                }
        Severity: Minor
        Found in includes/diff/DifferenceEngine.php - About 3 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 getDiffBody has 75 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function getDiffBody() {
                $this->mCacheHit = true;
                // Check if the diff should be hidden from this user
                if ( !$this->isContentOverridden ) {
                    if ( !$this->loadRevisionData() ) {
        Severity: Major
        Found in includes/diff/DifferenceEngine.php - About 3 hrs to fix

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

              public function renderNewRevision() {
                  if ( $this->isContentOverridden ) {
                      // The code below only works with a RevisionRecord object. We could construct a
                      // fake RevisionRecord (here or in setContent), but since this does not seem
                      // needed at the moment, we'll just fail for now.
          Severity: Minor
          Found in includes/diff/DifferenceEngine.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 loadRevisionData has 70 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function loadRevisionData() {
                  if ( $this->mRevisionsLoaded ) {
                      return $this->isContentOverridden ||
                      ( $this->mOldRevisionRecord !== null && $this->mNewRevisionRecord !== null );
                  }
          Severity: Major
          Found in includes/diff/DifferenceEngine.php - About 2 hrs to fix

            Method renderNewRevision has 68 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function renderNewRevision() {
                    if ( $this->isContentOverridden ) {
                        // The code below only works with a RevisionRecord object. We could construct a
                        // fake RevisionRecord (here or in setContent), but since this does not seem
                        // needed at the moment, we'll just fail for now.
            Severity: Major
            Found in includes/diff/DifferenceEngine.php - About 2 hrs to fix

              Method getMultiNotice has 61 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function getMultiNotice() {
                      // The notice only make sense if we are diffing two saved revisions of the same page.
                      if (
                          !$this->mOldRevisionRecord || !$this->mNewRevisionRecord
                          || !$this->mOldPage || !$this->mNewPage
              Severity: Major
              Found in includes/diff/DifferenceEngine.php - About 2 hrs to fix

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

                    public function getMultiNotice() {
                        // The notice only make sense if we are diffing two saved revisions of the same page.
                        if (
                            !$this->mOldRevisionRecord || !$this->mNewRevisionRecord
                            || !$this->mOldPage || !$this->mNewPage
                Severity: Minor
                Found in includes/diff/DifferenceEngine.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 getRevisionHeader has 52 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function getRevisionHeader( RevisionRecord $rev, $complete = '' ) {
                        $lang = $this->getLanguage();
                        $user = $this->getUser();
                        $revtimestamp = $rev->getTimestamp();
                        $timestamp = $lang->userTimeAndDate( $revtimestamp, $user );
                Severity: Major
                Found in includes/diff/DifferenceEngine.php - About 2 hrs to fix

                  Method addHeader has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
                          // shared.css sets diff in interface language/dir, but the actual content
                          // is often in a different language, mostly the page content language/dir
                          $header = Html::openElement( 'table', [
                              'class' => [
                  Severity: Major
                  Found in includes/diff/DifferenceEngine.php - About 2 hrs to fix

                    Consider simplifying this complex logical expression.
                    Open

                            if (
                                !$this->mOldRevisionRecord || !$this->mNewRevisionRecord
                                || !$this->mOldPage || !$this->mNewPage
                                || !$this->mOldPage->equals( $this->mNewPage )
                                || $this->mOldRevisionRecord->getId() === null
                    Severity: Critical
                    Found in includes/diff/DifferenceEngine.php - About 1 hr to fix

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

                          public function mapDiffPrevNext( $old, $new ) {
                              if ( $new === 'prev' ) {
                                  // Show diff between revision $old and the previous one. Get previous one from DB.
                                  $newid = intval( $old );
                                  $oldid = false;
                      Severity: Minor
                      Found in includes/diff/DifferenceEngine.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 addHeader has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
                              // shared.css sets diff in interface language/dir, but the actual content
                              // is often in a different language, mostly the page content language/dir
                              $header = Html::openElement( 'table', [
                                  'class' => [
                      Severity: Minor
                      Found in includes/diff/DifferenceEngine.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 getSlotDiffRenderers has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                      Open

                          protected function getSlotDiffRenderers() {
                              if ( $this->isSlotDiffRenderer ) {
                                  throw new LogicException( __METHOD__ . ' called in slot diff renderer mode' );
                              }
                      
                      
                      Severity: Minor
                      Found in includes/diff/DifferenceEngine.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 getMarkPatrolledLinkInfo has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          protected function getMarkPatrolledLinkInfo() {
                              $user = $this->getUser();
                              $config = $this->getConfig();
                      
                              // Prepare a change patrol link, if applicable
                      Severity: Minor
                      Found in includes/diff/DifferenceEngine.php - About 1 hr to fix

                        Method getSlotContents has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            protected function getSlotContents() {
                                if ( $this->isContentOverridden ) {
                                    return [
                                        SlotRecord::MAIN => [ 'old' => $this->mOldContent, 'new' => $this->mNewContent ]
                                    ];
                        Severity: Minor
                        Found in includes/diff/DifferenceEngine.php - About 1 hr to fix

                          Method loadText has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public function loadText() {
                                  if ( $this->mTextLoaded == 2 ) {
                                      return $this->loadRevisionData() &&
                                          ( $this->mOldRevisionRecord === false || $this->mOldContent )
                                          && $this->mNewContent;
                          Severity: Minor
                          Found in includes/diff/DifferenceEngine.php - About 1 hr to fix

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

                                protected function getMarkPatrolledLinkInfo() {
                                    $user = $this->getUser();
                                    $config = $this->getConfig();
                            
                                    // Prepare a change patrol link, if applicable
                            Severity: Minor
                            Found in includes/diff/DifferenceEngine.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 getSlotDiffRenderers has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                protected function getSlotDiffRenderers() {
                                    if ( $this->isSlotDiffRenderer ) {
                                        throw new LogicException( __METHOD__ . ' called in slot diff renderer mode' );
                                    }
                            
                            
                            Severity: Minor
                            Found in includes/diff/DifferenceEngine.php - About 1 hr to fix

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

                                  public function loadText() {
                                      if ( $this->mTextLoaded == 2 ) {
                                          return $this->loadRevisionData() &&
                                              ( $this->mOldRevisionRecord === false || $this->mOldContent )
                                              && $this->mNewContent;
                              Severity: Minor
                              Found in includes/diff/DifferenceEngine.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 __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                  public function __construct( $context = null, $old = 0, $new = 0, $rcid = 0,
                                      $refreshCache = false, $unhide = false
                              Severity: Minor
                              Found in includes/diff/DifferenceEngine.php - About 45 mins to fix

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

                                    public function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
                                Severity: Minor
                                Found in includes/diff/DifferenceEngine.php - About 35 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                              return false;
                                  Severity: Major
                                  Found in includes/diff/DifferenceEngine.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                            return true;
                                    Severity: Major
                                    Found in includes/diff/DifferenceEngine.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                          return $difftext;
                                      Severity: Major
                                      Found in includes/diff/DifferenceEngine.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                return $difftext;
                                        Severity: Major
                                        Found in includes/diff/DifferenceEngine.php - About 30 mins to fix

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

                                              public function getRevisionHeader( RevisionRecord $rev, $complete = '' ) {
                                                  $lang = $this->getLanguage();
                                                  $user = $this->getUser();
                                                  $revtimestamp = $rev->getTimestamp();
                                                  $timestamp = $lang->userTimeAndDate( $revtimestamp, $user );
                                          Severity: Minor
                                          Found in includes/diff/DifferenceEngine.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 2 locations. Consider refactoring.
                                          Open

                                                      if ( $hasPrevious ) {
                                                          $prevlinkQuery = [ 'diff' => 'prev', 'oldid' => $this->mOldid ] + $query;
                                                          $prevlink = $this->linkRenderer->makeKnownLink(
                                                              $this->mOldPage,
                                                              $this->msg( 'previousdiff' )->text(),
                                          Severity: Major
                                          Found in includes/diff/DifferenceEngine.php and 1 other location - About 1 hr to fix
                                          includes/diff/DifferenceEngine.php on lines 908..926

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

                                          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

                                                  if ( $samePage && $this->mNewPage && !$this->mNewRevisionRecord->isCurrent() ) {
                                                      $nextlinkQuery = [ 'diff' => 'next', 'oldid' => $this->mNewid ] + $query;
                                                      $nextlink = $this->linkRenderer->makeKnownLink(
                                                          $this->mNewPage,
                                                          $this->msg( 'nextdiff' )->text(),
                                          Severity: Major
                                          Found in includes/diff/DifferenceEngine.php and 1 other location - About 1 hr to fix
                                          includes/diff/DifferenceEngine.php on lines 846..864

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

                                          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