File ApiBase.php
has 1061 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Copyright © 2006, 2010 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
*
* This program is free software; you can redistribute it and/or modify
ApiBase
has 79 functions (exceeds 20 allowed). Consider refactoring. Open
abstract class ApiBase extends ContextSource {
use ApiBlockInfoTrait;
/** @var HookContainer */
Function extractRequestParams
has a Cognitive Complexity of 69 (exceeds 5 allowed). Consider refactoring. Open
public function extractRequestParams( $options = [] ) {
if ( is_bool( $options ) ) {
$options = [ 'parseLimit' => $options ];
}
$options += [
- 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 getFinalParamDescription
has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring. Open
public function getFinalParamDescription() {
$prefix = $this->getModulePrefix();
$name = $this->getModuleName();
$path = $this->getModulePath();
- 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 getFinalParamDescription
has 124 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getFinalParamDescription() {
$prefix = $this->getModulePrefix();
$name = $this->getModuleName();
$path = $this->getModulePath();
Method extractRequestParams
has 84 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function extractRequestParams( $options = [] ) {
if ( is_bool( $options ) ) {
$options = [ 'parseLimit' => $options ];
}
$options += [
Function getModuleSourceInfo
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
protected function getModuleSourceInfo() {
if ( $this->mModuleSource !== false ) {
return $this->mModuleSource;
}
- 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 getModuleSourceInfo
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getModuleSourceInfo() {
if ( $this->mModuleSource !== false ) {
return $this->mModuleSource;
}
Function getTitleOrPageId
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function getTitleOrPageId( $params, $load = false ) {
$this->requireOnlyOneParameter( $params, 'title', 'pageid' );
$pageObj = null;
if ( isset( $params['title'] ) ) {
- 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 dieStatus
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function dieStatus( StatusValue $status ) {
if ( $status->isGood() ) {
throw new InvalidArgumentException( 'Successful status passed to ApiBase::dieStatus' );
}
- 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 dieStatus
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function dieStatus( StatusValue $status ) {
if ( $status->isGood() ) {
throw new InvalidArgumentException( 'Successful status passed to ApiBase::dieStatus' );
}
Function getWatchlistUser
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function getWatchlistUser( $params ) {
if ( $params['owner'] !== null && $params['token'] !== null ) {
$services = MediaWikiServices::getInstance();
$user = $services->getUserFactory()->newFromName( $params['owner'], UserRigorOptions::RIGOR_NONE );
if ( !$user || !$user->isRegistered() ) {
- 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 getModuleFromPath
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getModuleFromPath( $path ) {
$module = $this->getMain();
if ( $path === 'main' ) {
return $module;
}
Function requirePostedParameters
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function requirePostedParameters( $params, $prefix = 'prefix' ) {
if ( !$this->mustBePosted() ) {
// In order to allow client code to choose the correct method (GET or POST) depending *only*
// on mustBePosted(), make sure that the module requires posting if any of its potential
// parameters require posting.
- 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 errorArrayToStatus
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function errorArrayToStatus( array $errors, Authority $performer = null ) {
$performer ??= $this->getAuthority();
$block = $performer->getBlock();
$status = Status::newGood();
- 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 getModuleFromPath
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getModuleFromPath( $path ) {
$module = $this->getMain();
if ( $path === 'main' ) {
return $module;
}
- 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 getTitleFromTitleOrPageId
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getTitleFromTitleOrPageId( $params ) {
$this->requireOnlyOneParameter( $params, 'title', 'pageid' );
$titleObj = null;
if ( isset( $params['title'] ) ) {
- 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 parseContinueParamOrDie
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function parseContinueParamOrDie( string $continue, array $types ): array {
$cont = explode( '|', $continue );
$this->dieContinueUsageIf( count( $cont ) != count( $types ) );
foreach ( $cont as $i => &$value ) {
- 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 checkTitleUserPermissions
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function checkTitleUserPermissions(
PageIdentity $pageIdentity,
$actions,
array $options = []
) {
- 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 addBlockInfoToStatus
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function addBlockInfoToStatus( StatusValue $status, Authority $user = null ) {
if ( $status instanceof PermissionStatus ) {
$block = $status->getBlock();
} else {
$user = $user ?: $this->getAuthority();
- 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 ( isset( $settings[SubmoduleDef::PARAM_SUBMODULE_MAP] ) ) {
$map = $settings[SubmoduleDef::PARAM_SUBMODULE_MAP];
} else {
$prefix = $this->isMain() ? '' : ( $this->getModulePath() . '+' );
$map = [];
- 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 92.
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