wikimedia/mediawiki-core

View on GitHub
includes/editpage/EditPage.php

Summary

Maintainability
F
1 mo
Test Coverage

File EditPage.php has 3014 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
Severity: Major
Found in includes/editpage/EditPage.php - About 1 wk to fix

    Method internalAttemptSave has 399 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function internalAttemptSave( &$result, $markAsBot = false, $markAsMinor = false ) {
            $useNPPatrol = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::UseNPPatrol );
            $useRCPatrol = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::UseRCPatrol );
            if ( !$this->getHookRunner()->onEditPage__attemptSave( $this ) ) {
                wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" );
    Severity: Major
    Found in includes/editpage/EditPage.php - About 1 day to fix

      EditPage has 93 functions (exceeds 20 allowed). Consider refactoring.
      Open

      #[\AllowDynamicProperties]
      class EditPage implements IEditObject {
          use DeprecationHelper;
          use ProtectedHookAccessorTrait;
      
      
      Severity: Major
      Found in includes/editpage/EditPage.php - About 1 day to fix

        Function getContentObject has a Cognitive Complexity of 77 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function getContentObject( $def_content = null ) {
                $services = MediaWikiServices::getInstance();
                $disableAnonTalk = $services->getMainConfig()->get( MainConfigNames::DisableAnonTalk );
                $request = $this->context->getRequest();
        
        
        Severity: Minor
        Found in includes/editpage/EditPage.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 internalAttemptSave has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring.
        Open

            public function internalAttemptSave( &$result, $markAsBot = false, $markAsMinor = false ) {
                $useNPPatrol = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::UseNPPatrol );
                $useRCPatrol = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::UseRCPatrol );
                if ( !$this->getHookRunner()->onEditPage__attemptSave( $this ) ) {
                    wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" );
        Severity: Minor
        Found in includes/editpage/EditPage.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

        Method showEditForm has 199 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function showEditForm() {
                # need to parse the preview early so that we know which templates are used,
                # otherwise users with "show preview after edit box" will get a blank list
                # we parse this near the beginning so that setHeaders can do the title
                # setting work instead of leaving it in getPreviewText
        Severity: Major
        Found in includes/editpage/EditPage.php - About 7 hrs to fix

          Method getContentObject has 148 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function getContentObject( $def_content = null ) {
                  $services = MediaWikiServices::getInstance();
                  $disableAnonTalk = $services->getMainConfig()->get( MainConfigNames::DisableAnonTalk );
                  $request = $this->context->getRequest();
          
          
          Severity: Major
          Found in includes/editpage/EditPage.php - About 5 hrs to fix

            Function getPreviewText has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getPreviewText() {
                    $out = $this->context->getOutput();
                    $config = $this->context->getConfig();
            
                    if ( $config->get( MainConfigNames::RawHtml ) && !$this->mTokenOk ) {
            Severity: Minor
            Found in includes/editpage/EditPage.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

            Function importFormDataPosted has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
            Open

                private function importFormDataPosted( WebRequest $request ): void {
                    # These fields need to be checked for encoding.
                    # Also remove trailing whitespace, but don't remove _initial_
                    # whitespace from the text boxes. This may be significant formatting.
                    $this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) );
            Severity: Minor
            Found in includes/editpage/EditPage.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

            Function showHeader has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
            Open

                private function showHeader(): void {
                    $out = $this->context->getOutput();
                    $user = $this->context->getUser();
                    if ( $this->isConflict ) {
                        $this->addExplainConflictHeader();
            Severity: Minor
            Found in includes/editpage/EditPage.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

            Method edit has 131 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function edit() {
                    // Allow extensions to modify/prevent this form or submission
                    if ( !$this->getHookRunner()->onAlternateEdit( $this ) ) {
                        return;
                    }
            Severity: Major
            Found in includes/editpage/EditPage.php - About 5 hrs to fix

              Method importFormDataPosted has 121 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function importFormDataPosted( WebRequest $request ): void {
                      # These fields need to be checked for encoding.
                      # Also remove trailing whitespace, but don't remove _initial_
                      # whitespace from the text boxes. This may be significant formatting.
                      $this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) );
              Severity: Major
              Found in includes/editpage/EditPage.php - About 4 hrs to fix

                Method getPreviewText has 117 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function getPreviewText() {
                        $out = $this->context->getOutput();
                        $config = $this->context->getConfig();
                
                        if ( $config->get( MainConfigNames::RawHtml ) && !$this->mTokenOk ) {
                Severity: Major
                Found in includes/editpage/EditPage.php - About 4 hrs to fix

                  Function showEditForm has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function showEditForm() {
                          # need to parse the preview early so that we know which templates are used,
                          # otherwise users with "show preview after edit box" will get a blank list
                          # we parse this near the beginning so that setHeaders can do the title
                          # setting work instead of leaving it in getPreviewText
                  Severity: Minor
                  Found in includes/editpage/EditPage.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 edit has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function edit() {
                          // Allow extensions to modify/prevent this form or submission
                          if ( !$this->getHookRunner()->onAlternateEdit( $this ) ) {
                              return;
                          }
                  Severity: Minor
                  Found in includes/editpage/EditPage.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

                  Method handleStatus has 97 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function handleStatus( Status $status, $resultDetails ): bool {
                          $statusValue = is_int( $status->value ) ? $status->value : 0;
                  
                          /**
                           * @todo FIXME: once the interface for internalAttemptSave() is made
                  Severity: Major
                  Found in includes/editpage/EditPage.php - About 3 hrs to fix

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

                        private function showHeader(): void {
                            $out = $this->context->getOutput();
                            $user = $this->context->getUser();
                            if ( $this->isConflict ) {
                                $this->addExplainConflictHeader();
                    Severity: Major
                    Found in includes/editpage/EditPage.php - About 3 hrs to fix

                      Method importFormData has 65 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function importFormData( &$request ) {
                              # Section edit can come from either the form or a link
                              $this->section = $request->getVal( 'wpSection', $request->getVal( 'section', '' ) );
                      
                              if ( $this->section !== null && $this->section !== '' && !$this->isSectionEditSupported() ) {
                      Severity: Major
                      Found in includes/editpage/EditPage.php - About 2 hrs to fix

                        Function importFormData has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function importFormData( &$request ) {
                                # Section edit can come from either the form or a link
                                $this->section = $request->getVal( 'wpSection', $request->getVal( 'section', '' ) );
                        
                                if ( $this->section !== null && $this->section !== '' && !$this->isSectionEditSupported() ) {
                        Severity: Minor
                        Found in includes/editpage/EditPage.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 setHeaders has 59 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            public function setHeaders() {
                                $out = $this->context->getOutput();
                        
                                $out->addModules( 'mediawiki.action.edit' );
                                $out->addModuleStyles( 'mediawiki.action.edit.styles' );
                        Severity: Major
                        Found in includes/editpage/EditPage.php - About 2 hrs to fix

                          Function showDiff has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function showDiff() {
                                  $oldtitlemsg = 'currentrev';
                                  # if message does not exist, show diff against the preloaded default
                                  if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI && !$this->mTitle->exists() ) {
                                      $oldtext = $this->mTitle->getDefaultMessageText();
                          Severity: Minor
                          Found in includes/editpage/EditPage.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 initialiseForm has 53 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              private function initialiseForm(): bool {
                                  $this->edittime = $this->page->getTimestamp();
                                  $this->editRevId = $this->page->getLatest();
                          
                                  $dummy = $this->contentHandlerFactory
                          Severity: Major
                          Found in includes/editpage/EditPage.php - About 2 hrs to fix

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

                                public function showDiff() {
                                    $oldtitlemsg = 'currentrev';
                                    # if message does not exist, show diff against the preloaded default
                                    if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI && !$this->mTitle->exists() ) {
                                        $oldtext = $this->mTitle->getDefaultMessageText();
                            Severity: Minor
                            Found in includes/editpage/EditPage.php - About 1 hr to fix

                              Method getEditButtons has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  public function getEditButtons( &$tabindex ) {
                                      $buttons = [];
                              
                                      $labelAsPublish =
                                          $this->context->getConfig()->get( MainConfigNames::EditSubmitButtonLabelPublish );
                              Severity: Minor
                              Found in includes/editpage/EditPage.php - About 1 hr to fix

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

                                    public static function getPreviewLimitReport( ParserOutput $output = null ) {
                                        if ( !$output || !$output->getLimitReportData() ) {
                                            return '';
                                        }
                                
                                
                                Severity: Minor
                                Found in includes/editpage/EditPage.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 displayViewSourcePage has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    private function displayViewSourcePage( Content $content, string $errorMessage ): void {
                                        $out = $this->context->getOutput();
                                        $this->getHookRunner()->onEditPage__showReadOnlyForm_initial( $this, $out );
                                
                                        $out->setRobotPolicy( 'noindex,nofollow' );
                                Severity: Minor
                                Found in includes/editpage/EditPage.php - About 1 hr to fix

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

                                      private function getLastDelete(): ?stdClass {
                                          $dbr = $this->connectionProvider->getReplicaDatabase();
                                          $commentQuery = $this->commentStore->getJoin( 'log_comment' );
                                          $data = $dbr->selectRow(
                                              array_merge( [ 'logging' ], $commentQuery['tables'], [ 'actor' ] ),
                                  Severity: Minor
                                  Found in includes/editpage/EditPage.php - About 1 hr to fix

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

                                        public function getCheckboxesWidget( &$tabindex, $values ) {
                                            $checkboxes = [];
                                            $checkboxesDef = $this->getCheckboxesDefinition( $values );
                                    
                                            foreach ( $checkboxesDef as $name => $options ) {
                                    Severity: Minor
                                    Found in includes/editpage/EditPage.php - About 1 hr to fix

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

                                          private function getCheckboxesDefinitionForWatchlist( $watch, $watchexpiry ): array {
                                              $fieldDefs = [
                                                  'wpWatchthis' => [
                                                      'id' => 'wpWatchthis',
                                                      'label-message' => 'watchthis',
                                      Severity: Minor
                                      Found in includes/editpage/EditPage.php - About 1 hr to fix

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

                                            public static function getPreviewLimitReport( ParserOutput $output = null ) {
                                                if ( !$output || !$output->getLimitReportData() ) {
                                                    return '';
                                                }
                                        
                                        
                                        Severity: Minor
                                        Found in includes/editpage/EditPage.php - About 1 hr to fix

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

                                              private function showIntro(): void {
                                                  $services = MediaWikiServices::getInstance();
                                          
                                                  // Hardcoded list of notices that are suppressable for historical reasons.
                                                  // This feature was originally added for LiquidThreads, to avoid showing non-essential messages
                                          Severity: Minor
                                          Found in includes/editpage/EditPage.php - About 1 hr to fix

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

                                                public function setHeaders() {
                                                    $out = $this->context->getOutput();
                                            
                                                    $out->addModules( 'mediawiki.action.edit' );
                                                    $out->addModuleStyles( 'mediawiki.action.edit.styles' );
                                            Severity: Minor
                                            Found in includes/editpage/EditPage.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 __construct has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                                            Open

                                                public function __construct( Article $article ) {
                                                    $this->mArticle = $article;
                                                    $this->page = $article->getPage(); // model object
                                                    $this->mTitle = $article->getTitle();
                                            
                                            
                                            Severity: Minor
                                            Found in includes/editpage/EditPage.php - About 1 hr to fix

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

                                                  protected function showStandardInputs( &$tabindex = 2 ) {
                                                      $out = $this->context->getOutput();
                                                      $out->addHTML( "<div class='editOptions'>\n" );
                                              
                                                      if ( $this->section !== 'new' ) {
                                              Severity: Minor
                                              Found in includes/editpage/EditPage.php - About 1 hr to fix

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

                                                    private function isUndoClean( Content $content ): bool {
                                                        // Check whether the undo was "clean", that is the user has not modified
                                                        // the automatically generated content.
                                                        $undoRev = $this->revisionStore->getRevisionById( $this->undidRev );
                                                        if ( $undoRev === null ) {
                                                Severity: Minor
                                                Found in includes/editpage/EditPage.php - About 1 hr to fix

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

                                                      private function initialiseForm(): bool {
                                                          $this->edittime = $this->page->getTimestamp();
                                                          $this->editRevId = $this->page->getLatest();
                                                  
                                                          $dummy = $this->contentHandlerFactory
                                                  Severity: Minor
                                                  Found in includes/editpage/EditPage.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 addLongPageWarningHeader has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                                  Open

                                                      private function addLongPageWarningHeader(): void {
                                                          if ( $this->contentLength === false ) {
                                                              $this->contentLength = strlen( $this->textbox1 );
                                                          }
                                                  
                                                  
                                                  Severity: Minor
                                                  Found in includes/editpage/EditPage.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 getTemplates has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                                  Open

                                                      public function getTemplates() {
                                                          if ( $this->preview || $this->section !== '' ) {
                                                              $templates = [];
                                                              if ( !isset( $this->mParserOutput ) ) {
                                                                  return $templates;
                                                  Severity: Minor
                                                  Found in includes/editpage/EditPage.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 handleFailedConstraint has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                                  Open

                                                      private function handleFailedConstraint( IEditConstraint $failed ): void {
                                                          if ( $failed instanceof PageSizeConstraint ) {
                                                              // Error will be displayed by showEditForm()
                                                              $this->tooBig = true;
                                                          } elseif ( $failed instanceof UserBlockConstraint ) {
                                                  Severity: Minor
                                                  Found in includes/editpage/EditPage.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 handleStatus has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                                  Open

                                                      private function handleStatus( Status $status, $resultDetails ): bool {
                                                          $statusValue = is_int( $status->value ) ? $status->value : 0;
                                                  
                                                          /**
                                                           * @todo FIXME: once the interface for internalAttemptSave() is made
                                                  Severity: Minor
                                                  Found in includes/editpage/EditPage.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 mergeChangesIntoContent has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                                  Open

                                                      private function mergeChangesIntoContent( Content $editContent ) {
                                                          // This is the revision that was current at the time editing was initiated on the client,
                                                          // even if the edit was based on an old revision.
                                                          $baseRevRecord = $this->getExpectedParentRevision();
                                                          $baseContent = $baseRevRecord ?
                                                  Severity: Minor
                                                  Found in includes/editpage/EditPage.php - About 1 hr to fix

                                                    Method getUndoContent has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                                    Open

                                                        private function getUndoContent( RevisionRecord $undoRev, RevisionRecord $oldRev, &$error ) {
                                                            $handler = $this->contentHandlerFactory
                                                                ->getContentHandler( $undoRev->getSlot(
                                                                    SlotRecord::MAIN,
                                                                    RevisionRecord::RAW
                                                    Severity: Minor
                                                    Found in includes/editpage/EditPage.php - About 1 hr to fix

                                                      Method displayPreviewArea has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                                      Open

                                                          private function displayPreviewArea( string $previewOutput, bool $isOnTop ): void {
                                                              $attribs = [ 'id' => 'wikiPreview' ];
                                                              if ( $isOnTop ) {
                                                                  $attribs['class'] = 'ontop';
                                                              }
                                                      Severity: Minor
                                                      Found in includes/editpage/EditPage.php - About 1 hr to fix

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

                                                            protected function previewOnOpen() {
                                                                $config = $this->context->getConfig();
                                                                $previewOnOpenNamespaces = $config->get( MainConfigNames::PreviewOnOpenNamespaces );
                                                                $request = $this->context->getRequest();
                                                                if ( $config->get( MainConfigNames::RawHtml ) ) {
                                                        Severity: Minor
                                                        Found in includes/editpage/EditPage.php - About 55 mins to fix

                                                        Cognitive Complexity

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

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

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

                                                        Further reading

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

                                                            public function maybeActivateTempUserCreate( $doAcquire ): Status {
                                                                if ( $this->tempUserCreateActive ) {
                                                                    // Already done
                                                                    return Status::newGood();
                                                                }
                                                        Severity: Minor
                                                        Found in includes/editpage/EditPage.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 wasDeletedSinceLastEdit has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                                        Open

                                                            private function wasDeletedSinceLastEdit(): bool {
                                                                if ( $this->deletedSinceEdit !== null ) {
                                                                    return $this->deletedSinceEdit;
                                                                }
                                                        
                                                        
                                                        Severity: Minor
                                                        Found in includes/editpage/EditPage.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 isUndoClean has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                        Open

                                                            private function isUndoClean( Content $content ): bool {
                                                                // Check whether the undo was "clean", that is the user has not modified
                                                                // the automatically generated content.
                                                                $undoRev = $this->revisionStore->getRevisionById( $this->undidRev );
                                                                if ( $undoRev === null ) {
                                                        Severity: Minor
                                                        Found in includes/editpage/EditPage.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;
                                                        Severity: Major
                                                        Found in includes/editpage/EditPage.php - About 30 mins to fix

                                                          Avoid too many return statements within this method.
                                                          Open

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

                                                            Avoid too many return statements within this method.
                                                            Open

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

                                                              Avoid too many return statements within this method.
                                                              Open

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

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                                return Status::newGood( self::AS_CONFLICT_DETECTED )->setOK( false );
                                                                Severity: Major
                                                                Found in includes/editpage/EditPage.php - About 30 mins to fix

                                                                  Avoid too many return statements within this method.
                                                                  Open

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

                                                                    Avoid too many return statements within this method.
                                                                    Open

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

                                                                      Avoid too many return statements within this method.
                                                                      Open

                                                                              return Status::newGood( $statusCode );
                                                                      Severity: Major
                                                                      Found in includes/editpage/EditPage.php - About 30 mins to fix

                                                                        Avoid too many return statements within this method.
                                                                        Open

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

                                                                          Avoid too many return statements within this method.
                                                                          Open

                                                                                      return $doEditStatus;
                                                                          Severity: Major
                                                                          Found in includes/editpage/EditPage.php - About 30 mins to fix

                                                                            Avoid too many return statements within this method.
                                                                            Open

                                                                                            return Status::wrap( $failed->getLegacyStatus() );
                                                                            Severity: Major
                                                                            Found in includes/editpage/EditPage.php - About 30 mins to fix

                                                                              Avoid too many return statements within this method.
                                                                              Open

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

                                                                                Avoid too many return statements within this method.
                                                                                Open

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

                                                                                  Avoid too many return statements within this method.
                                                                                  Open

                                                                                              return Status::wrap( $failed->getLegacyStatus() );
                                                                                  Severity: Major
                                                                                  Found in includes/editpage/EditPage.php - About 30 mins to fix

                                                                                    Avoid too many return statements within this method.
                                                                                    Open

                                                                                                return Status::wrap( $failed->getLegacyStatus() );
                                                                                    Severity: Major
                                                                                    Found in includes/editpage/EditPage.php - About 30 mins to fix

                                                                                      Avoid too many return statements within this method.
                                                                                      Open

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

                                                                                        Avoid too many return statements within this method.
                                                                                        Open

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

                                                                                          Avoid too many return statements within this method.
                                                                                          Open

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

                                                                                            Avoid too many return statements within this method.
                                                                                            Open

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

                                                                                              Avoid too many return statements within this method.
                                                                                              Open

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

                                                                                                Avoid too many return statements within this method.
                                                                                                Open

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

                                                                                                  Avoid too many return statements within this method.
                                                                                                  Open

                                                                                                                  return Status::wrap( $failed->getLegacyStatus() );
                                                                                                  Severity: Major
                                                                                                  Found in includes/editpage/EditPage.php - About 30 mins to fix

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

                                                                                                        private function getCheckboxesDefinitionForWatchlist( $watch, $watchexpiry ): array {
                                                                                                            $fieldDefs = [
                                                                                                                'wpWatchthis' => [
                                                                                                                    'id' => 'wpWatchthis',
                                                                                                                    'label-message' => 'watchthis',
                                                                                                    Severity: Minor
                                                                                                    Found in includes/editpage/EditPage.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 displayViewSourcePage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                                    Open

                                                                                                        private function displayViewSourcePage( Content $content, string $errorMessage ): void {
                                                                                                            $out = $this->context->getOutput();
                                                                                                            $this->getHookRunner()->onEditPage__showReadOnlyForm_initial( $this, $out );
                                                                                                    
                                                                                                            $out->setRobotPolicy( 'noindex,nofollow' );
                                                                                                    Severity: Minor
                                                                                                    Found in includes/editpage/EditPage.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 displayPreviewArea has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                                    Open

                                                                                                        private function displayPreviewArea( string $previewOutput, bool $isOnTop ): void {
                                                                                                            $attribs = [ 'id' => 'wikiPreview' ];
                                                                                                            if ( $isOnTop ) {
                                                                                                                $attribs['class'] = 'ontop';
                                                                                                            }
                                                                                                    Severity: Minor
                                                                                                    Found in includes/editpage/EditPage.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 getUserForPreview has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                                    Open

                                                                                                        private function getUserForPreview() {
                                                                                                            if ( $this->savedTempUser ) {
                                                                                                                return $this->savedTempUser;
                                                                                                            } elseif ( $this->unsavedTempUser ) {
                                                                                                                return $this->unsavedTempUser;
                                                                                                    Severity: Minor
                                                                                                    Found in includes/editpage/EditPage.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

                                                                                                            $buttons['preview'] = new OOUI\ButtonInputWidget( [
                                                                                                                'name' => 'wpPreview',
                                                                                                                'tabIndex' => ++$tabindex,
                                                                                                                'id' => 'wpPreviewWidget',
                                                                                                                'inputId' => 'wpPreview',
                                                                                                    Severity: Major
                                                                                                    Found in includes/editpage/EditPage.php and 1 other location - About 1 hr to fix
                                                                                                    includes/editpage/EditPage.php on lines 4448..4464

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

                                                                                                    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

                                                                                                            $buttons['diff'] = new OOUI\ButtonInputWidget( [
                                                                                                                'name' => 'wpDiff',
                                                                                                                'tabIndex' => ++$tabindex,
                                                                                                                'id' => 'wpDiffWidget',
                                                                                                                'inputId' => 'wpDiff',
                                                                                                    Severity: Major
                                                                                                    Found in includes/editpage/EditPage.php and 1 other location - About 1 hr to fix
                                                                                                    includes/editpage/EditPage.php on lines 4430..4446

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

                                                                                                    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