Showing 11,545 of 11,545 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
OO.ui.RadioInputWidget.prototype.restorePreInfuseState = function ( state ) {
OO.ui.RadioInputWidget.super.prototype.restorePreInfuseState.call( this, state );
if ( state.checked !== undefined && state.checked !== this.isSelected() ) {
this.setSelected( state.checked );
}
- 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 114.
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
Method getWatchedItemsWithRecentChangeInfo
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getWatchedItemsWithRecentChangeInfo(
User $user, array $options = [], &$startFrom = null
) {
$options += [
'includeFields' => [],
File RollbackPage.php
has 330 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
Method buildPersonalUrls
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function buildPersonalUrls( bool $includeNotifications = true ) {
$this->setupTemplateContext();
$title = $this->getTitle();
$authority = $this->getAuthority();
$request = $this->getRequest();
Method loadFromDB
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function loadFromDB( $code, $mode = null ) {
$icp = MediaWikiServices::getInstance()->getConnectionProvider();
$dbr = ( $mode === self::FOR_UPDATE ) ? $icp->getPrimaryDatabase() : $icp->getReplicaDatabase();
Method formatNumInternal
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function formatNumInternal(
string $number, bool $noTranslate, bool $noSeparators
): string {
$translateNumerals = $this->config->get( MainConfigNames::TranslateNumerals );
Method segmentSplitter
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function segmentSplitter( $filename ) {
$showXMP = XMPReader::isSupported();
$segmentCount = 0;
File LinkCache.php
has 330 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Page existence cache.
*
* This program is free software; you can redistribute it and/or modify
Method getAllowedParams
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getAllowedParams() {
return [
'title' => null,
'text' => [
ParamValidator::PARAM_TYPE => 'text',
Method execute
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function execute() {
$this->useTransactionalTimeLimit();
$user = $this->getUser();
$params = $this->extractRequestParams();
Method execute
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function execute() {
$params = $this->extractRequestParams();
$done = [];
foreach ( $params['prop'] as $p ) {
switch ( $p ) {
Method outputPageList
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function outputPageList( $groups ) {
$out = $this->getOutput();
// Legend
$includesRestrictedPages = false;
Method execute
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function execute( $par ) {
$user = $this->getUser();
$request = $this->getRequest();
$session = $request->getSession();
$out = $this->getOutput();
File LinkHolderArray.php
has 330 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Holder of replacement pairs for wiki links
*
* This program is free software; you can redistribute it and/or modify
Function useFloating
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
function useFloating(reference, floating, options) {
if (options === void 0) {
options = {};
}
const whileElementsMountedOption = options.whileElementsMounted;
- 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 getNamespaceRestrictionLevels
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
public function getNamespaceRestrictionLevels( $index, UserIdentity $user = null ): array {
if ( !isset( $this->options->get( MainConfigNames::NamespaceProtection )[$index] ) ) {
// All levels are valid if there's no namespace restriction.
// But still filter by user, if necessary
$levels = $this->options->get( MainConfigNames::RestrictionLevels );
- 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 generateContentOutput
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
private function generateContentOutput(
Authority $performer,
ParserOptions $parserOptions,
int $oldid,
OutputPage $outputPage,
- 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 prepareContent
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
public function prepareContent(
UserIdentity $user,
RevisionSlotsUpdate $slotsUpdate,
$useStash = true
) {
- 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 prepareUpdate
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
public function prepareUpdate( RevisionRecord $revision, array $options = [] ) {
Assert::parameter(
!isset( $options['oldrevision'] )
|| $options['oldrevision'] instanceof RevisionRecord,
'$options["oldrevision"]',
- 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 doImport
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
public function doImport() {
$this->syntaxCheckXML();
// Calls to reader->read need to be wrapped in calls to
// libxml_disable_entity_loader() to avoid local 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"