wikimedia/mediawiki-core

View on GitHub
includes/specials/SpecialUpload.php

Summary

Maintainability
F
1 wk
Test Coverage

File SpecialUpload.php has 811 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

    Function showUploadWarning has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function showUploadWarning( $warnings ) {
            # If there are no warnings, or warnings we can ignore, return early.
            # mDestWarningAck is set when some javascript has shown the warning
            # to the user. mForReUpload is set when the user clicks the "upload a
            # new version" link.
    Severity: Minor
    Found in includes/specials/SpecialUpload.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 showUploadWarning has 89 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function showUploadWarning( $warnings ) {
            # If there are no warnings, or warnings we can ignore, return early.
            # mDestWarningAck is set when some javascript has shown the warning
            # to the user. mForReUpload is set when the user clicks the "upload a
            # new version" link.
    Severity: Major
    Found in includes/specials/SpecialUpload.php - About 3 hrs to fix

      Method showUploadStatus has 78 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function showUploadStatus( $user ) {
              // first, let's fetch the status from the main stash
              $progress = UploadBase::getSessionStatus( $user, $this->mCacheKey );
              if ( !$progress ) {
                  $progress = [ 'status' => Status::newFatal( 'invalid-cache-key' ) ];
      Severity: Major
      Found in includes/specials/SpecialUpload.php - About 3 hrs to fix

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

            protected function showUploadStatus( $user ) {
                // first, let's fetch the status from the main stash
                $progress = UploadBase::getSessionStatus( $user, $this->mCacheKey );
                if ( !$progress ) {
                    $progress = [ 'status' => Status::newFatal( 'invalid-cache-key' ) ];
        Severity: Minor
        Found in includes/specials/SpecialUpload.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

        SpecialUpload has 25 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class SpecialUpload extends SpecialPage {
        
            private LocalRepo $localRepo;
            private UserOptionsLookup $userOptionsLookup;
            private NamespaceInfo $nsInfo;
        Severity: Minor
        Found in includes/specials/SpecialUpload.php - About 2 hrs to fix

          Method processVerificationError has 59 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function processVerificationError( $details ) {
                  switch ( $details['status'] ) {
                      /** Statuses that only require name changing */
                      case UploadBase::MIN_LENGTH_PARTNAME:
                          $this->showRecoverableUploadError( $this->msg( 'minlength1' )->escaped() );
          Severity: Major
          Found in includes/specials/SpecialUpload.php - About 2 hrs to fix

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

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

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

                  protected function processVerificationError( $details ) {
                      switch ( $details['status'] ) {
                          /** Statuses that only require name changing */
                          case UploadBase::MIN_LENGTH_PARTNAME:
                              $this->showRecoverableUploadError( $this->msg( 'minlength1' )->escaped() );
              Severity: Minor
              Found in includes/specials/SpecialUpload.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 getUploadForm has 54 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) {
                      # Initialize form
                      $form = new UploadForm(
                          [
                              'watch' => $this->getWatchCheck(),
              Severity: Major
              Found in includes/specials/SpecialUpload.php - About 2 hrs to fix

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

                    private function showUploadProgress( $options ) {
                        // $isActive = $options['active'] ?? false;
                        //$progressBarProperty = $isActive ? '' : 'disabled';
                        $message = $this->msg( $options['msg'] )->escaped();
                        $destUrl = $this->mRequest->getText( 'wpDestUrl', '' );
                Severity: Minor
                Found in includes/specials/SpecialUpload.php - About 1 hr to fix

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

                      public function execute( $par ) {
                          $this->useTransactionalTimeLimit();
                  
                          $this->setHeaders();
                          $this->outputHeader();
                  Severity: Minor
                  Found in includes/specials/SpecialUpload.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 processAsyncUpload has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function processAsyncUpload() {
                          // Ensure the upload we're dealing with is an UploadFromUrl
                          if ( !$this->mUpload instanceof \UploadFromUrl ) {
                              $this->showUploadError( $this->msg( 'uploaderror' )->escaped() );
                  
                  
                  Severity: Minor
                  Found in includes/specials/SpecialUpload.php - About 1 hr to fix

                    Method loadRequest has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        protected function loadRequest() {
                            $this->mRequest = $request = $this->getRequest();
                            $this->mSourceType = $request->getVal( 'wpSourceType', 'file' );
                            $this->mUpload = UploadBase::createFromRequest( $request );
                            $this->mUploadClicked = $request->wasPosted()
                    Severity: Minor
                    Found in includes/specials/SpecialUpload.php - About 1 hr to fix

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

                          protected function performUploadChecks( $fetchFileStatus ): bool {
                              if ( !$fetchFileStatus->isOK() ) {
                                  $this->showUploadError( $this->getOutput()->parseAsInterface(
                                      $fetchFileStatus->getWikiText( false, false, $this->getLanguage() )
                                  ) );
                      Severity: Minor
                      Found in includes/specials/SpecialUpload.php - About 1 hr to fix

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

                            public static function getInitialPageText( $comment = '', $license = '',
                                $copyStatus = '', $source = '', Config $config = null
                            ) {
                                if ( $config === null ) {
                                    wfDebug( __METHOD__ . ' called without a Config instance passed to it' );
                        Severity: Minor
                        Found in includes/specials/SpecialUpload.php - About 1 hr to fix

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

                              protected function processUpload() {
                                  // Fetch the file if required
                                  $status = $this->mUpload->fetchFile();
                                  if ( !$this->performUploadChecks( $status ) ) {
                                      return;
                          Severity: Minor
                          Found in includes/specials/SpecialUpload.php - About 1 hr to fix

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

                                protected function loadRequest() {
                                    $this->mRequest = $request = $this->getRequest();
                                    $this->mSourceType = $request->getVal( 'wpSourceType', 'file' );
                                    $this->mUpload = UploadBase::createFromRequest( $request );
                                    $this->mUploadClicked = $request->wasPosted()
                            Severity: Minor
                            Found in includes/specials/SpecialUpload.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 getInitialPageText has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public static function getInitialPageText( $comment = '', $license = '',
                                    $copyStatus = '', $source = '', Config $config = null
                                ) {
                                    if ( $config === null ) {
                                        wfDebug( __METHOD__ . ' called without a Config instance passed to it' );
                            Severity: Minor
                            Found in includes/specials/SpecialUpload.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 showUploadProgress has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                                private function showUploadProgress( $options ) {
                                    // $isActive = $options['active'] ?? false;
                                    //$progressBarProperty = $isActive ? '' : 'disabled';
                                    $message = $this->msg( $options['msg'] )->escaped();
                                    $destUrl = $this->mRequest->getText( 'wpDestUrl', '' );
                            Severity: Minor
                            Found in includes/specials/SpecialUpload.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 performUploadChecks has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                                protected function performUploadChecks( $fetchFileStatus ): bool {
                                    if ( !$fetchFileStatus->isOK() ) {
                                        $this->showUploadError( $this->getOutput()->parseAsInterface(
                                            $fetchFileStatus->getWikiText( false, false, $this->getLanguage() )
                                        ) );
                            Severity: Minor
                            Found in includes/specials/SpecialUpload.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 getPageTextAndTags has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                                protected function getPageTextAndTags() {
                                    // Get the page text if this is not a reupload
                                    if ( !$this->mForReUpload ) {
                                        $pageText = self::getInitialPageText( $this->mComment, $this->mLicense,
                                            $this->mCopyrightStatus, $this->mCopyrightSource,
                            Severity: Minor
                            Found in includes/specials/SpecialUpload.php - About 45 mins to fix

                            Cognitive Complexity

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

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

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

                            Further reading

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

                                public static function getInitialPageText( $comment = '', $license = '',
                                    $copyStatus = '', $source = '', Config $config = null
                            Severity: Minor
                            Found in includes/specials/SpecialUpload.php - About 35 mins to fix

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

                                  public static function getExistsWarning( $exists ) {
                                      if ( !$exists ) {
                                          return '';
                                      }
                              
                              
                              Severity: Minor
                              Found in includes/specials/SpecialUpload.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 true;
                              Severity: Major
                              Found in includes/specials/SpecialUpload.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

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

                                  Avoid too many return statements within this method.
                                  Open

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

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

                                        protected function getWatchCheck() {
                                            $user = $this->getUser();
                                            if ( $this->userOptionsLookup->getBoolOption( $user, 'watchdefault' ) ) {
                                                // Watch all edits!
                                                return true;
                                    Severity: Minor
                                    Found in includes/specials/SpecialUpload.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

                                    There are no issues that match your filters.

                                    Category
                                    Status