wikimedia/mediawiki-core

View on GitHub
includes/media/SvgHandler.php

Summary

Maintainability
D
3 days
Test Coverage

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

<?php
/**
 * Handler for SVG images.
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Minor
Found in includes/media/SvgHandler.php - About 5 hrs to fix

    SvgHandler has 29 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class SvgHandler extends ImageHandler {
        public const SVG_METADATA_VERSION = 2;
    
        private const SVG_DEFAULT_RENDER_LANG = 'en';
    
    
    Severity: Minor
    Found in includes/media/SvgHandler.php - About 3 hrs to fix

      Method doTransform has 69 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
              if ( !$this->normaliseParams( $image, $params ) ) {
                  return new TransformParameterError( $params );
              }
              $clientWidth = $params['width'];
      Severity: Major
      Found in includes/media/SvgHandler.php - About 2 hrs to fix

        Method rasterize has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function rasterize( $srcPath, $dstPath, $width, $height, $lang = false ) {
                $mainConfig = MediaWikiServices::getInstance()->getMainConfig();
                $svgConverters = $mainConfig->get( MainConfigNames::SVGConverters );
                $svgConverter = $mainConfig->get( MainConfigNames::SVGConverter );
                $svgConverterPath = $mainConfig->get( MainConfigNames::SVGConverterPath );
        Severity: Minor
        Found in includes/media/SvgHandler.php - About 1 hr to fix

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

              public function rasterize( $srcPath, $dstPath, $width, $height, $lang = false ) {
                  $mainConfig = MediaWikiServices::getInstance()->getMainConfig();
                  $svgConverters = $mainConfig->get( MainConfigNames::SVGConverters );
                  $svgConverter = $mainConfig->get( MainConfigNames::SVGConverter );
                  $svgConverterPath = $mainConfig->get( MainConfigNames::SVGConverterPath );
          Severity: Minor
          Found in includes/media/SvgHandler.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 doTransform has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
                  if ( !$this->normaliseParams( $image, $params ) ) {
                      return new TransformParameterError( $params );
                  }
                  $clientWidth = $params['width'];
          Severity: Minor
          Found in includes/media/SvgHandler.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 formatMetadata has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

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

            Function getMatchedLanguage has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getMatchedLanguage( $userPreferredLanguage, array $svgLanguages ) {
                    // Explicitly requested undetermined language (text without svg systemLanguage attribute)
                    if ( $userPreferredLanguage === 'und' ) {
                        return 'und';
                    }
            Severity: Minor
            Found in includes/media/SvgHandler.php - About 55 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 getCommonMetaArray has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getCommonMetaArray( File $file ) {
                    $metadata = $this->validateMetadata( $file->getMetadataArray() );
                    if ( !$metadata || isset( $metadata['error'] ) ) {
                        return [];
                    }
            Severity: Minor
            Found in includes/media/SvgHandler.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

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

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

                  public function rasterize( $srcPath, $dstPath, $width, $height, $lang = false ) {
              Severity: Minor
              Found in includes/media/SvgHandler.php - About 35 mins to fix

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

                    public function formatMetadata( $file, $context = false ) {
                        $result = [
                            'visible' => [],
                            'collapsed' => []
                        ];
                Severity: Minor
                Found in includes/media/SvgHandler.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 $status; // MediaTransformError
                Severity: Major
                Found in includes/media/SvgHandler.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return new MediaTransformError( 'thumbnail_error',
                                  $params['width'], $params['height'],
                                  wfMessage( 'thumbnail-temp-create' )->text()
                              );
                  Severity: Major
                  Found in includes/media/SvgHandler.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return new MediaTransformError( 'thumbnail_error',
                                    $params['width'], $params['height'],
                                    wfMessage( 'filemissing' )
                                );
                    Severity: Major
                    Found in includes/media/SvgHandler.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return new ThumbnailImage( $image, $dstUrl, $dstPath, $params );
                      Severity: Major
                      Found in includes/media/SvgHandler.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight,
                                        wfMessage( 'thumbnail_dest_directory' ) );
                        Severity: Major
                        Found in includes/media/SvgHandler.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return new MediaTransformError( 'thumbnail_error',
                                          $params['width'], $params['height'],
                                          wfMessage( 'thumbnail-temp-create' )
                                      );
                          Severity: Major
                          Found in includes/media/SvgHandler.php - About 30 mins to fix

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

                                public function getAvailableLanguages( File $file ) {
                                    $langList = [];
                                    $metadata = $this->validateMetadata( $file->getMetadataArray() );
                                    if ( isset( $metadata['translations'] ) ) {
                                        foreach ( $metadata['translations'] as $lang => $langType ) {
                            Severity: Minor
                            Found in includes/media/SvgHandler.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 normaliseParamsInternal has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                                protected function normaliseParamsInternal( $image, $params ) {
                                    $svgMaxSize = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::SVGMaxSize );
                            
                                    # Don't make an image bigger than wgMaxSVGSize on the smaller side
                                    if ( $params['physicalWidth'] <= $params['physicalHeight'] ) {
                            Severity: Minor
                            Found in includes/media/SvgHandler.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