wikimedia/mediawiki-core

View on GitHub
includes/filerepo/ForeignAPIRepo.php

Summary

Maintainability
D
2 days
Test Coverage

File ForeignAPIRepo.php has 369 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: Minor
Found in includes/filerepo/ForeignAPIRepo.php - About 4 hrs to fix

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

        public function fileExistsBatch( array $files ) {
            $results = [];
            foreach ( $files as $k => $f ) {
                if ( isset( $this->mFileExists[$f] ) ) {
                    $results[$k] = $this->mFileExists[$f];
    Severity: Minor
    Found in includes/filerepo/ForeignAPIRepo.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 getThumbUrlFromCache has 63 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getThumbUrlFromCache( $name, $width, $height, $params = "" ) {
            // We can't check the local cache using FileRepo functions because
            // we override fileExistsBatch(). We have to use the FileBackend directly.
            $backend = $this->getBackend(); // convenience
    
    
    Severity: Major
    Found in includes/filerepo/ForeignAPIRepo.php - About 2 hrs to fix

      Method fileExistsBatch has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function fileExistsBatch( array $files ) {
              $results = [];
              foreach ( $files as $k => $f ) {
                  if ( isset( $this->mFileExists[$f] ) ) {
                      $results[$k] = $this->mFileExists[$f];
      Severity: Minor
      Found in includes/filerepo/ForeignAPIRepo.php - About 1 hr to fix

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

            public function getThumbUrlFromCache( $name, $width, $height, $params = "" ) {
                // We can't check the local cache using FileRepo functions because
                // we override fileExistsBatch(). We have to use the FileBackend directly.
                $backend = $this->getBackend(); // convenience
        
        
        Severity: Minor
        Found in includes/filerepo/ForeignAPIRepo.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 getImageInfo has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            public function getImageInfo( $data ) {
                if ( $data && isset( $data['query']['pages'] ) ) {
                    foreach ( $data['query']['pages'] as $info ) {
                        if ( isset( $info['imageinfo'][0] ) ) {
                            $return = $info['imageinfo'][0];
        Severity: Minor
        Found in includes/filerepo/ForeignAPIRepo.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 httpGet has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function httpGet(
                $url, $timeout = 'default', $options = [], &$mtime = false
            ) {
                $options['timeout'] = $timeout;
                $url = MediaWikiServices::getInstance()->getUrlUtils()
        Severity: Minor
        Found in includes/filerepo/ForeignAPIRepo.php - About 1 hr to fix

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

              public function __construct( $info ) {
                  $localFileRepo = MediaWikiServices::getInstance()->getMainConfig()
                      ->get( MainConfigNames::LocalFileRepo );
                  parent::__construct( $info );
          
          
          Severity: Minor
          Found in includes/filerepo/ForeignAPIRepo.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 getThumbUrl has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                  $name, $width = -1, $height = -1, &$result = null, $otherParams = ''
          Severity: Minor
          Found in includes/filerepo/ForeignAPIRepo.php - About 35 mins to fix

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

                    $name, $width = -1, $height = -1, $otherParams = '', $lang = null
            Severity: Minor
            Found in includes/filerepo/ForeignAPIRepo.php - About 35 mins to fix

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

                  public function findBySha1( $hash ) {
                      $results = $this->fetchImageQuery( [
                          'aisha1base36' => $hash,
                          'aiprop' => ForeignAPIFile::getProps(),
                          'list' => 'allimages',
              Severity: Minor
              Found in includes/filerepo/ForeignAPIRepo.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 $foreignUrl;
              Severity: Major
              Found in includes/filerepo/ForeignAPIRepo.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

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

                  Avoid too many return statements within this method.
                  Open

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

                    Avoid too many return statements within this method.
                    Open

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

                      There are no issues that match your filters.

                      Category
                      Status