wikimedia/mediawiki-core

View on GitHub
includes/filerepo/file/File.php

Summary

Maintainability
F
1 wk
Test Coverage

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

<?php
/**
 * @defgroup FileAbstraction File abstraction
 * @ingroup FileRepo
 *
Severity: Major
Found in includes/filerepo/file/File.php - About 2 days to fix

    File has 135 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class File implements MediaHandlerState {
        use ProtectedHookAccessorTrait;
    
        // Bitfield values akin to the revision deletion constants
        public const DELETED_FILE = 1;
    Severity: Major
    Found in includes/filerepo/file/File.php - About 2 days to fix

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

          public function transform( $params, $flags = 0 ) {
              $thumbnailEpoch = MediaWikiServices::getInstance()->getMainConfig()
                  ->get( MainConfigNames::ThumbnailEpoch );
      
              do {
      Severity: Minor
      Found in includes/filerepo/file/File.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 transform has 70 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function transform( $params, $flags = 0 ) {
              $thumbnailEpoch = MediaWikiServices::getInstance()->getMainConfig()
                  ->get( MainConfigNames::ThumbnailEpoch );
      
              do {
      Severity: Major
      Found in includes/filerepo/file/File.php - About 2 hrs to fix

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

            public function getThumbnailSource( $params ) {
                if ( $this->repo
                    && $this->getHandler()->supportsBucketing()
                    && isset( $params['physicalWidth'] )
                    && $bucket = $this->getThumbnailBucket( $params['physicalWidth'] )
        Severity: Minor
        Found in includes/filerepo/file/File.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 generateAndSaveThumb has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function generateAndSaveThumb( $tmpFile, $transformParams, $flags ) {
                $ignoreImageErrors = MediaWikiServices::getInstance()->getMainConfig()
                    ->get( MainConfigNames::IgnoreImageErrors );
        
                if ( !$this->repo->canTransformLocally() ) {
        Severity: Major
        Found in includes/filerepo/file/File.php - About 2 hrs to fix

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

              public function getThumbnailSource( $params ) {
                  if ( $this->repo
                      && $this->getHandler()->supportsBucketing()
                      && isset( $params['physicalWidth'] )
                      && $bucket = $this->getThumbnailBucket( $params['physicalWidth'] )
          Severity: Minor
          Found in includes/filerepo/file/File.php - About 1 hr to fix

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

                public function generateAndSaveThumb( $tmpFile, $transformParams, $flags ) {
                    $ignoreImageErrors = MediaWikiServices::getInstance()->getMainConfig()
                        ->get( MainConfigNames::IgnoreImageErrors );
            
                    if ( !$this->repo->canTransformLocally() ) {
            Severity: Minor
            Found in includes/filerepo/file/File.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 generateBucketsIfNeeded has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function generateBucketsIfNeeded( $params, $flags = 0 ) {
                    if ( !$this->repo
                        || !isset( $params['physicalWidth'] )
                        || !isset( $params['physicalHeight'] )
                    ) {
            Severity: Minor
            Found in includes/filerepo/file/File.php - About 1 hr to fix

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

                  public static function normalizeTitle( $title, $exception = false ) {
                      $ret = $title;
              
                      if ( !$ret instanceof Title ) {
                          if ( $ret instanceof PageIdentity ) {
              Severity: Minor
              Found in includes/filerepo/file/File.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 getDescriptionText has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function getDescriptionText( Language $lang = null ) {
                      global $wgLang;
              
                      if ( !$this->repo || !$this->repo->fetchDescription ) {
                          return false;
              Severity: Minor
              Found in includes/filerepo/file/File.php - About 1 hr to fix

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

                    public function getThumbnailBucket( $desiredWidth, $page = 1 ) {
                        $thumbnailBuckets = MediaWikiServices::getInstance()
                            ->getMainConfig()->get( MainConfigNames::ThumbnailBuckets );
                        $thumbnailMinimumBucketDistance = MediaWikiServices::getInstance()
                            ->getMainConfig()->get( MainConfigNames::ThumbnailMinimumBucketDistance );
                Severity: Minor
                Found in includes/filerepo/file/File.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 getIsSafeFileUncached has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function getIsSafeFileUncached() {
                        $trustedMediaFormats = MediaWikiServices::getInstance()->getMainConfig()
                            ->get( MainConfigNames::TrustedMediaFormats );
                
                        if ( $this->allowInlineDisplay() ) {
                Severity: Minor
                Found in includes/filerepo/file/File.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

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

                    public function getDisplayWidthHeight( $maxWidth, $maxHeight, $page = 1 ) {
                        if ( !$maxWidth || !$maxHeight ) {
                            // should never happen
                            throw new ConfigException( 'Using a choice from $wgImageLimits that is 0x0' );
                        }
                Severity: Minor
                Found in includes/filerepo/file/File.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/filerepo/file/File.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return false;
                  Severity: Major
                  Found in includes/filerepo/file/File.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return true;
                    Severity: Major
                    Found in includes/filerepo/file/File.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return false; # unknown type, not trusted
                      Severity: Major
                      Found in includes/filerepo/file/File.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        return $bucket;
                        Severity: Major
                        Found in includes/filerepo/file/File.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return false;
                          Severity: Major
                          Found in includes/filerepo/file/File.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return false;
                            Severity: Major
                            Found in includes/filerepo/file/File.php - About 30 mins to fix

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

                                  protected function generateBucketsIfNeeded( $params, $flags = 0 ) {
                                      if ( !$this->repo
                                          || !isset( $params['physicalWidth'] )
                                          || !isset( $params['physicalHeight'] )
                                      ) {
                              Severity: Minor
                              Found in includes/filerepo/file/File.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 getTransformScript has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  private function getTransformScript() {
                                      if ( !isset( $this->transformScript ) ) {
                                          $this->transformScript = false;
                                          if ( $this->repo ) {
                                              $script = $this->repo->getThumbScriptUrl();
                              Severity: Minor
                              Found in includes/filerepo/file/File.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