wikimedia/mediawiki-core

View on GitHub
includes/specials/SpecialUndelete.php

Summary

Maintainability
F
1 wk
Test Coverage

File SpecialUndelete.php has 1294 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Implements Special:Undelete
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Major
Found in includes/specials/SpecialUndelete.php - About 3 days to fix

    Method showHistory has 261 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function showHistory() {
            $this->checkReadOnly();
    
            $out = $this->getOutput();
            if ( $this->mAllowed ) {
    Severity: Major
    Found in includes/specials/SpecialUndelete.php - About 1 day to fix

      Method showRevision has 176 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function showRevision( $timestamp ) {
              if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
                  return;
              }
              $out = $this->getOutput();
      Severity: Major
      Found in includes/specials/SpecialUndelete.php - About 7 hrs to fix

        Function showHistory has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function showHistory() {
                $this->checkReadOnly();
        
                $out = $this->getOutput();
                if ( $this->mAllowed ) {
        Severity: Minor
        Found in includes/specials/SpecialUndelete.php - About 5 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        SpecialUndelete has 29 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class SpecialUndelete extends SpecialPage {
        
            /**
             * Limit of revisions (Page history) to display.
             * (If there are more items to display - "Load more" button will appear).
        Severity: Minor
        Found in includes/specials/SpecialUndelete.php - About 3 hrs to fix

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

              public function execute( $par ) {
                  $this->useTransactionalTimeLimit();
          
                  $user = $this->getUser();
          
          
          Severity: Minor
          Found in includes/specials/SpecialUndelete.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

          Function showRevision has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
          Open

              private function showRevision( $timestamp ) {
                  if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
                      return;
                  }
                  $out = $this->getOutput();
          Severity: Minor
          Found in includes/specials/SpecialUndelete.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 formatRevisionRow has 76 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
                  $revRecord = $this->revisionStore->newRevisionFromArchiveRow(
                          $row,
                          IDBAccessObject::READ_NORMAL,
                          $this->mTargetObj
          Severity: Major
          Found in includes/specials/SpecialUndelete.php - About 3 hrs to fix

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

                private function loadRequest( $par ) {
                    $request = $this->getRequest();
                    $user = $this->getUser();
            
                    $this->mAction = $request->getRawVal( 'action' );
            Severity: Minor
            Found in includes/specials/SpecialUndelete.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 loadRequest has 67 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function loadRequest( $par ) {
                    $request = $this->getRequest();
                    $user = $this->getUser();
            
                    $this->mAction = $request->getRawVal( 'action' );
            Severity: Major
            Found in includes/specials/SpecialUndelete.php - About 2 hrs to fix

              Function formatRevisionRow has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
                      $revRecord = $this->revisionStore->newRevisionFromArchiveRow(
                              $row,
                              IDBAccessObject::READ_NORMAL,
                              $this->mTargetObj
              Severity: Minor
              Found in includes/specials/SpecialUndelete.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 diffHeader has 63 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function diffHeader( RevisionRecord $revRecord, $prefix ) {
                      if ( $revRecord instanceof RevisionArchiveRecord ) {
                          // Revision in the archive table, only viewable via this special page
                          $targetPage = $this->getPageTitle();
                          $targetQuery = [
              Severity: Major
              Found in includes/specials/SpecialUndelete.php - About 2 hrs to fix

                Method showSearchForm has 60 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private function showSearchForm() {
                        $out = $this->getOutput();
                        $out->setPageTitleMsg( $this->msg( 'undelete-search-title' ) );
                        $fuzzySearch = $this->getRequest()->getVal( 'fuzzy', '1' );
                
                
                Severity: Major
                Found in includes/specials/SpecialUndelete.php - About 2 hrs to fix

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

                      public function execute( $par ) {
                          $this->useTransactionalTimeLimit();
                  
                          $user = $this->getUser();
                  
                  
                  Severity: Major
                  Found in includes/specials/SpecialUndelete.php - About 2 hrs to fix

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

                        private function undelete() {
                            if ( $this->getConfig()->get( MainConfigNames::UploadMaintenance )
                                && $this->mTargetObj->getNamespace() === NS_FILE
                            ) {
                                throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
                    Severity: Minor
                    Found in includes/specials/SpecialUndelete.php - About 1 hr to fix

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

                              PermissionManager $permissionManager,
                              RevisionStore $revisionStore,
                              RevisionRenderer $revisionRenderer,
                              IContentHandlerFactory $contentHandlerFactory,
                              NameTableStore $changeTagDefStore,
                      Severity: Major
                      Found in includes/specials/SpecialUndelete.php - About 1 hr to fix

                        Method showList has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            private function showList( $result ) {
                                $out = $this->getOutput();
                        
                                if ( $result->numRows() == 0 ) {
                                    $out->addWikiMsg( 'undelete-no-results' );
                        Severity: Minor
                        Found in includes/specials/SpecialUndelete.php - About 1 hr to fix

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

                              private function formatFileRow( $row ) {
                                  $file = ArchivedFile::newFromRow( $row );
                                  $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
                                  $user = $this->getUser();
                          
                          
                          Severity: Minor
                          Found in includes/specials/SpecialUndelete.php - About 1 hr to fix

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

                                private function formatFileRow( $row ) {
                                    $file = ArchivedFile::newFromRow( $row );
                                    $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
                                    $user = $this->getUser();
                            
                            
                            Severity: Minor
                            Found in includes/specials/SpecialUndelete.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 getFileLink has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                private function getFileLink( $file, $titleObj, $ts, $key ) {
                                    $user = $this->getUser();
                                    $time = $this->getLanguage()->userTimeAndDate( $ts, $user );
                            
                                    if ( !$file->userCan( File::DELETED_FILE, $user ) ) {
                            Severity: Minor
                            Found in includes/specials/SpecialUndelete.php - About 1 hr to fix

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

                                  private function diffHeader( RevisionRecord $revRecord, $prefix ) {
                                      if ( $revRecord instanceof RevisionArchiveRecord ) {
                                          // Revision in the archive table, only viewable via this special page
                                          $targetPage = $this->getPageTitle();
                                          $targetQuery = [
                              Severity: Minor
                              Found in includes/specials/SpecialUndelete.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

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

                                  private function undelete() {
                                      if ( $this->getConfig()->get( MainConfigNames::UploadMaintenance )
                                          && $this->mTargetObj->getNamespace() === NS_FILE
                                      ) {
                                          throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
                              Severity: Minor
                              Found in includes/specials/SpecialUndelete.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

                              Avoid too many return statements within this method.
                              Open

                                                  return;
                              Severity: Major
                              Found in includes/specials/SpecialUndelete.php - About 30 mins to fix

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

                                    private function redirectToRevDel() {
                                        $revisions = [];
                                
                                        foreach ( $this->getRequest()->getValues() as $key => $val ) {
                                            $matches = [];
                                Severity: Minor
                                Found in includes/specials/SpecialUndelete.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 4 locations. Consider refactoring.
                                Open

                                    public function __construct(
                                        PermissionManager $permissionManager,
                                        RevisionStore $revisionStore,
                                        RevisionRenderer $revisionRenderer,
                                        IContentHandlerFactory $contentHandlerFactory,
                                Severity: Major
                                Found in includes/specials/SpecialUndelete.php and 3 other locations - About 1 hr to fix
                                includes/Permissions/PermissionManager.php on lines 283..316
                                includes/auth/AuthManager.php on lines 260..294
                                includes/page/UndeletePage.php on lines 126..159

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

                                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