File ApiUpload.php
has 871 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Copyright © 2008 - 2010 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
*
* This program is free software; you can redistribute it and/or modify
Function selectUploadModule
has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring. Open
protected function selectUploadModule() {
// chunk or one and only one of the following parameters is needed
if ( !$this->mParams['chunk'] ) {
$this->requireOnlyOneParameter( $this->mParams,
'filekey', 'file', 'url' );
- 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 getChunkResult
has 152 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getChunkResult( $warnings ) {
$result = [];
if ( $warnings && count( $warnings ) > 0 ) {
$result['warnings'] = $warnings;
Method performUpload
has 103 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function performUpload( $warnings ) {
// Use comment as initial page text by default
$this->mParams['text'] ??= $this->mParams['comment'];
/** @var LocalFile $file */
Method selectUploadModule
has 95 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function selectUploadModule() {
// chunk or one and only one of the following parameters is needed
if ( !$this->mParams['chunk'] ) {
$this->requireOnlyOneParameter( $this->mParams,
'filekey', 'file', 'url' );
Function getChunkResult
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
private function getChunkResult( $warnings ) {
$result = [];
if ( $warnings && count( $warnings ) > 0 ) {
$result['warnings'] = $warnings;
- 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
ApiUpload
has 26 functions (exceeds 20 allowed). Consider refactoring. Open
class ApiUpload extends ApiBase {
use ApiWatchlistTrait;
/** @var UploadBase|UploadFromChunks */
Function performUpload
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
protected function performUpload( $warnings ) {
// Use comment as initial page text by default
$this->mParams['text'] ??= $this->mParams['comment'];
/** @var LocalFile $file */
- 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 checkVerification
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function checkVerification( array $verification ) {
switch ( $verification['status'] ) {
// Recoverable errors
case UploadBase::MIN_LENGTH_PARTNAME:
$this->dieRecoverableError( [ 'filename-tooshort' ], 'filename' );
Method execute
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function execute() {
// Check whether upload is enabled
if ( !UploadBase::isEnabled() ) {
$this->dieWithError( 'uploaddisabled' );
}
Function execute
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function execute() {
// Check whether upload is enabled
if ( !UploadBase::isEnabled() ) {
$this->dieWithError( 'uploaddisabled' );
}
- 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 verifyUpload
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
protected function verifyUpload() {
if ( $this->mParams['chunk'] ) {
$maxSize = UploadBase::getMaxUploadSize();
if ( $this->mParams['filesize'] > $maxSize ) {
$this->dieWithError( 'file-too-large' );
- 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 getAllowedParams
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getAllowedParams() {
$params = [
'filename' => [
ParamValidator::PARAM_TYPE => 'string',
],
Method performStash
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function performStash( $failureMode, &$data = null ) {
$isPartial = (bool)$this->mParams['chunk'];
try {
$status = $this->mUpload->tryStashFile( $this->getUser(), $isPartial );
Function transformWarnings
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
protected function transformWarnings( $warnings ) {
if ( $warnings ) {
// Add indices
ApiResult::setIndexedTagName( $warnings, 'warning' );
- 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 handleStashException
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function handleStashException( $e ) {
$this->log->info( "Upload stashing of {filename} failed for {user} because {error}",
[
'user' => $this->getUser()->getName(),
'error' => get_class( $e ),
Method transformWarnings
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function transformWarnings( $warnings ) {
if ( $warnings ) {
// Add indices
ApiResult::setIndexedTagName( $warnings, 'warning' );
Method verifyUpload
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function verifyUpload() {
if ( $this->mParams['chunk'] ) {
$maxSize = UploadBase::getMaxUploadSize();
if ( $this->mParams['filesize'] > $maxSize ) {
$this->dieWithError( 'file-too-large' );
Function handleStashException
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function handleStashException( $e ) {
$this->log->info( "Upload stashing of {filename} failed for {user} because {error}",
[
'user' => $this->getUser()->getName(),
'error' => get_class( $e ),
- 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 __construct
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
ApiMain $mainModule,
$moduleName,
JobQueueGroup $jobQueueGroup,
WatchlistManager $watchlistManager,
UserOptionsLookup $userOptionsLookup
Function performStash
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function performStash( $failureMode, &$data = null ) {
$isPartial = (bool)$this->mParams['chunk'];
try {
$status = $this->mUpload->tryStashFile( $this->getUser(), $isPartial );
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if ( $this->mParams['filekey'] ) {
$job = new PublishStashedFileJob(
[
'filename' => $this->mParams['filename'],
'filekey' => $this->mParams['filekey'],
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 108.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
} elseif ( $this->mParams['url'] ) {
$job = new UploadFromUrlJob(
[
'filename' => $this->mParams['filename'],
'url' => $this->mParams['url'],
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 108.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76