wikimedia/mediawiki-core

View on GitHub
includes/filerepo/FileRepo.php

Summary

Maintainability
F
1 wk
Test Coverage

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

<?php
/**
 * @defgroup FileRepo File Repository
 *
 * @brief This module handles how MediaWiki interacts with filesystems.
Severity: Major
Found in includes/filerepo/FileRepo.php - About 2 days to fix

    FileRepo has 84 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class FileRepo {
        public const DELETE_SOURCE = 1;
        public const OVERWRITE = 2;
        public const OVERWRITE_SAME = 4;
        public const SKIP_LOCKING = 8;
    Severity: Major
    Found in includes/filerepo/FileRepo.php - About 1 day to fix

      Function findFile has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          public function findFile( $title, $options = [] ) {
              if ( !empty( $options['private'] ) && !( $options['private'] instanceof Authority ) ) {
                  throw new InvalidArgumentException(
                      __METHOD__ . ' called with the `private` option set to something ' .
                      'other than an Authority object'
      Severity: Minor
      Found in includes/filerepo/FileRepo.php - About 3 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

      Method publishBatch has 72 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function publishBatch( array $ntuples, $flags = 0 ) {
              $this->assertWritableRepo(); // fail out if read-only
      
              $backend = $this->backend; // convenience
              // Try creating directories
      Severity: Major
      Found in includes/filerepo/FileRepo.php - About 2 hrs to fix

        Function publishBatch has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

            public function publishBatch( array $ntuples, $flags = 0 ) {
                $this->assertWritableRepo(); // fail out if read-only
        
                $backend = $this->backend; // convenience
                // Try creating directories
        Severity: Minor
        Found in includes/filerepo/FileRepo.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 findFile has 58 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function findFile( $title, $options = [] ) {
                if ( !empty( $options['private'] ) && !( $options['private'] instanceof Authority ) ) {
                    throw new InvalidArgumentException(
                        __METHOD__ . ' called with the `private` option set to something ' .
                        'other than an Authority object'
        Severity: Major
        Found in includes/filerepo/FileRepo.php - About 2 hrs to fix

          Method __construct has 55 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function __construct( array $info = null ) {
                  // Verify required settings presence
                  if (
                      $info === null
                      || !array_key_exists( 'name', $info )
          Severity: Major
          Found in includes/filerepo/FileRepo.php - About 2 hrs to fix

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

                public function __construct( array $info = null ) {
                    // Verify required settings presence
                    if (
                        $info === null
                        || !array_key_exists( 'name', $info )
            Severity: Minor
            Found in includes/filerepo/FileRepo.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

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

                public function findFiles( array $items, $flags = 0 ) {
                    $result = [];
                    foreach ( $items as $item ) {
                        if ( is_array( $item ) ) {
                            $title = $item['title'];
            Severity: Minor
            Found in includes/filerepo/FileRepo.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 storeBatch has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function storeBatch( array $triplets, $flags = 0 ) {
                    $this->assertWritableRepo(); // fail out if read-only
            
                    if ( $flags & self::DELETE_SOURCE ) {
                        throw new InvalidArgumentException( "DELETE_SOURCE not supported in " . __METHOD__ );
            Severity: Minor
            Found in includes/filerepo/FileRepo.php - About 1 hr to fix

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

                  public function storeBatch( array $triplets, $flags = 0 ) {
                      $this->assertWritableRepo(); // fail out if read-only
              
                      if ( $flags & self::DELETE_SOURCE ) {
                          throw new InvalidArgumentException( "DELETE_SOURCE not supported in " . __METHOD__ );
              Severity: Minor
              Found in includes/filerepo/FileRepo.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 findFileFromKey has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function findFileFromKey( $sha1, $options = [] ) {
                      if ( !empty( $options['private'] ) && !( $options['private'] instanceof Authority ) ) {
                          throw new InvalidArgumentException(
                              __METHOD__ . ' called with the `private` option set to something ' .
                              'other than an Authority object'
              Severity: Minor
              Found in includes/filerepo/FileRepo.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 findFileFromKey has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function findFileFromKey( $sha1, $options = [] ) {
                      if ( !empty( $options['private'] ) && !( $options['private'] instanceof Authority ) ) {
                          throw new InvalidArgumentException(
                              __METHOD__ . ' called with the `private` option set to something ' .
                              'other than an Authority object'
              Severity: Minor
              Found in includes/filerepo/FileRepo.php - About 1 hr to fix

                Method findFiles has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function findFiles( array $items, $flags = 0 ) {
                        $result = [];
                        foreach ( $items as $item ) {
                            if ( is_array( $item ) ) {
                                $title = $item['title'];
                Severity: Minor
                Found in includes/filerepo/FileRepo.php - About 1 hr to fix

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

                      public function quickImportBatch( array $triples ) {
                          $status = $this->newGood();
                          $operations = [];
                          foreach ( $triples as $triple ) {
                              [ $src, $dst ] = $triple;
                  Severity: Minor
                  Found in includes/filerepo/FileRepo.php - About 1 hr to fix

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

                        public function deleteBatch( array $sourceDestPairs ) {
                            $this->assertWritableRepo(); // fail out if read-only
                    
                            // Try creating directories
                            $this->initZones( [ 'public', 'deleted' ] );
                    Severity: Minor
                    Found in includes/filerepo/FileRepo.php - About 1 hr to fix

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

                          public function quickImportBatch( array $triples ) {
                              $status = $this->newGood();
                              $operations = [];
                              foreach ( $triples as $triple ) {
                                  [ $src, $dst ] = $triple;
                      Severity: Minor
                      Found in includes/filerepo/FileRepo.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 getInfo has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function getInfo() {
                              $ret = [
                                  'name' => $this->getName(),
                                  'displayname' => $this->getDisplayName(),
                                  'rootUrl' => $this->getZoneUrl( 'public' ),
                      Severity: Minor
                      Found in includes/filerepo/FileRepo.php - About 1 hr to fix

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

                                $src, $dstRel, $archiveRel, $flags = 0, array $options = []
                        Severity: Minor
                        Found in includes/filerepo/FileRepo.php - About 35 mins to fix

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

                              protected function enumFilesInStorage( $callback ) {
                                  $publicRoot = $this->getZonePath( 'public' );
                                  $numDirs = 1 << ( $this->hashLevels * 4 );
                                  // Use a priori assumptions about directory structure
                                  // to reduce the tree height of the scanning process.
                          Severity: Minor
                          Found in includes/filerepo/FileRepo.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 false;
                          Severity: Major
                          Found in includes/filerepo/FileRepo.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

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

                              Avoid too many return statements within this method.
                              Open

                                              return $img;
                              Severity: Major
                              Found in includes/filerepo/FileRepo.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                        return $img;
                                Severity: Major
                                Found in includes/filerepo/FileRepo.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

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

                                    Avoid too many return statements within this method.
                                    Open

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

                                      Avoid too many return statements within this method.
                                      Open

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

                                        Avoid too many return statements within this method.
                                        Open

                                                        return $this->thumbUrl;
                                        Severity: Major
                                        Found in includes/filerepo/FileRepo.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                          return "{$this->url}/transcoded";
                                          Severity: Major
                                          Found in includes/filerepo/FileRepo.php - About 30 mins to fix

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

                                                public function newFile( $title, $time = false ) {
                                                    $title = File::normalizeTitle( $title );
                                                    if ( !$title ) {
                                                        return null;
                                                    }
                                            Severity: Minor
                                            Found in includes/filerepo/FileRepo.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 deleteBatch has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                                public function deleteBatch( array $sourceDestPairs ) {
                                                    $this->assertWritableRepo(); // fail out if read-only
                                            
                                                    // Try creating directories
                                                    $this->initZones( [ 'public', 'deleted' ] );
                                            Severity: Minor
                                            Found in includes/filerepo/FileRepo.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 getZoneUrl has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                                public function getZoneUrl( $zone, $ext = null ) {
                                                    if ( in_array( $zone, [ 'public', 'thumb', 'transcoded' ] ) ) {
                                                        // standard public zones
                                                        if ( $ext !== null && isset( $this->zones[$zone]['urlsByExt'][$ext] ) ) {
                                                            // custom URL for extension/zone
                                            Severity: Minor
                                            Found in includes/filerepo/FileRepo.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 getDescriptionRenderUrl has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                                public function getDescriptionRenderUrl( $name, $lang = null ) {
                                                    $query = 'action=render';
                                                    if ( $lang !== null ) {
                                                        $query .= '&uselang=' . urlencode( $lang );
                                                    }
                                            Severity: Minor
                                            Found in includes/filerepo/FileRepo.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