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
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';
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'];
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 );
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 );
- Read upRead up
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'];
- Read upRead up
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' => []
];
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';
}
- Read upRead up
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 [];
}
- Read upRead up
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 ) {
Method rasterize
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function rasterize( $srcPath, $dstPath, $width, $height, $lang = false ) {
Function formatMetadata
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function formatMetadata( $file, $context = false ) {
$result = [
'visible' => [],
'collapsed' => []
];
- Read upRead up
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
Avoid too many return
statements within this method. Open
return new MediaTransformError( 'thumbnail_error',
$params['width'], $params['height'],
wfMessage( 'thumbnail-temp-create' )->text()
);
Avoid too many return
statements within this method. Open
return new MediaTransformError( 'thumbnail_error',
$params['width'], $params['height'],
wfMessage( 'filemissing' )
);
Avoid too many return
statements within this method. Open
return new ThumbnailImage( $image, $dstUrl, $dstPath, $params );
Avoid too many return
statements within this method. Open
return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight,
wfMessage( 'thumbnail_dest_directory' ) );
Avoid too many return
statements within this method. Open
return new MediaTransformError( 'thumbnail_error',
$params['width'], $params['height'],
wfMessage( 'thumbnail-temp-create' )
);
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 ) {
- Read upRead up
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'] ) {
- Read upRead up
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"