wikimedia/mediawiki-core

View on GitHub
includes/media/MediaHandler.php

Summary

Maintainability
F
3 days
Test Coverage

MediaHandler has 62 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class MediaHandler {
    public const TRANSFORM_LATER = 1;
    public const METADATA_GOOD = true;
    public const METADATA_BAD = false;
    public const METADATA_COMPATIBLE = 2; // for old but backwards compatible.
Severity: Major
Found in includes/media/MediaHandler.php - About 1 day to fix

    File MediaHandler.php has 358 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/media/MediaHandler.php - About 4 hrs to fix

      Function getSizeAndMetadataWithFallback has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          final public function getSizeAndMetadataWithFallback( $file, $path ) {
              if ( !$this->useLegacyMetadata() ) {
                  if ( $file instanceof MediaHandlerState ) {
                      $state = $file;
                  } else {
      Severity: Minor
      Found in includes/media/MediaHandler.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 getSizeAndMetadataWithFallback has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          final public function getSizeAndMetadataWithFallback( $file, $path ) {
              if ( !$this->useLegacyMetadata() ) {
                  if ( $file instanceof MediaHandlerState ) {
                      $state = $file;
                  } else {
      Severity: Major
      Found in includes/media/MediaHandler.php - About 2 hrs to fix

        Function getPageRangesByDimensions has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function getPageRangesByDimensions( $pagesByDimensions ) {
                $pageRangesByDimensions = [];
        
                foreach ( $pagesByDimensions as $dimensions => $pageList ) {
                    $ranges = [];
        Severity: Minor
        Found in includes/media/MediaHandler.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 formatMetadataHelper has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function formatMetadataHelper( $metadataArray, $context = false ) {
                $result = [
                    'visible' => [],
                    'collapsed' => []
                ];
        Severity: Minor
        Found in includes/media/MediaHandler.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 formatMetadataHelper has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function formatMetadataHelper( $metadataArray, $context = false ) {
                $result = [
                    'visible' => [],
                    'collapsed' => []
                ];
        Severity: Minor
        Found in includes/media/MediaHandler.php - About 1 hr to fix

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

              public static function getPageRangesByDimensions( $pagesByDimensions ) {
                  $pageRangesByDimensions = [];
          
                  foreach ( $pagesByDimensions as $dimensions => $pageList ) {
                      $ranges = [];
          Severity: Minor
          Found in includes/media/MediaHandler.php - About 1 hr to fix

            Method addMeta has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                protected static function addMeta( &$array, $visibility, $type, $id, $value, $param = false ) {
            Severity: Minor
            Found in includes/media/MediaHandler.php - About 45 mins to fix

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

                  public function removeBadFile( $dstPath, $retval = 0 ) {
                      if ( file_exists( $dstPath ) ) {
                          $thumbstat = stat( $dstPath );
                          if ( $thumbstat['size'] == 0 || $retval != 0 ) {
                              $result = unlink( $dstPath );
              Severity: Minor
              Found in includes/media/MediaHandler.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 doTransform has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  abstract public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 );
              Severity: Minor
              Found in includes/media/MediaHandler.php - About 35 mins to fix

                There are no issues that match your filters.

                Category
                Status