Showing 11,545 of 11,545 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
OO.ui.SelectWidget.prototype.findFirstSelectedItem = function () {
for ( let i = 0; i < this.items.length; i++ ) {
if ( this.items[ i ].isSelected() ) {
return this.items[ i ];
}
- 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 99.
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
DerivativeContext
has 27 functions (exceeds 20 allowed). Consider refactoring. Open
class DerivativeContext extends Context {
private const INHERIT_VALUE = -1;
/**
* @var Context
SqlBlobStore
has 27 functions (exceeds 20 allowed). Consider refactoring. Open
class SqlBlobStore implements BlobStore {
// Note: the name has been taken unchanged from the old Revision class.
public const TEXT_CACHE_GROUP = 'revisiontext:10';
MimeAnalyzer
has 27 functions (exceeds 20 allowed). Consider refactoring. Open
class MimeAnalyzer implements LoggerAwareInterface {
/** @var string */
protected $typeFile;
/** @var string */
protected $infoFile;
PostgresUpdater
has 27 functions (exceeds 20 allowed). Consider refactoring. Open
class PostgresUpdater extends DatabaseUpdater {
/**
* @var DatabasePostgres
*/
MainConfigSchema
has 27 functions (exceeds 20 allowed). Consider refactoring. Open
class MainConfigSchema {
use JsonSchemaTrait;
/**
* Returns a generator for iterating over all config settings and their default values.
HtmlOutputRendererHelper
has 27 functions (exceeds 20 allowed). Consider refactoring. Open
class HtmlOutputRendererHelper implements HtmlOutputHelper {
use RestAuthorizeTrait;
use RestStatusTrait;
/**
Function updateUI
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
mw.widgets.datetime.CalendarWidget.prototype.updateUI = function () {
let row, day, k, $cell,
width = this.minWidth;
const
Function fetch
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
function fetch(input, init) {
return new Promise(function(resolve, reject) {
var request = new Request(input, init);
if (request.signal && request.signal.aborted) {
Method getButtons
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getButtons() {
$buttons = [];
if ( $this->mShowSubmit ) {
$value = $this->getSubmitText();
Method applyDefaultConfig
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function applyDefaultConfig( array $lbConf ): array {
$this->options->assertRequiredOptions( self::APPLY_DEFAULT_CONFIG_OPTIONS );
$typesWithSchema = self::getDbTypesWithSchemas();
if ( Profiler::instance() instanceof ProfilerStub ) {
Method processTitlesArray
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function processTitlesArray( $titles ) {
$linkBatch = $this->linkBatchFactory->newLinkBatch();
/** @var Title[] $titleObjects */
$titleObjects = [];
Method postHtml
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function postHtml() {
$links = [];
$this->getOutput()->addModuleStyles( 'mediawiki.special' );
Method doHeader
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function doHeader( $opts, $numRows ) {
$this->setTopText( $opts );
$defaults = $opts->getAllValues();
$nondefaults = $opts->getChangedValues();
Method genParserOutput
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function genParserOutput(
PageConfig $pageConfig, ParserOptions $options, ?ParserOutput $previousOutput
): ParserOutput {
$parserOutput = new ParserOutput();
Method stashFile
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function stashFile( $path, $sourceType = null, $fileProps = null ) {
if ( !is_file( $path ) ) {
wfDebug( __METHOD__ . " tried to stash file at '$path', but it doesn't exist" );
throw new UploadStashBadPathException(
wfMessage( 'uploadstash-bad-path' )
Method execute
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function execute() {
# Change to current working directory
$oldCwd = getcwd();
chdir( $oldCwd );
Method execute
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function execute() {
if ( !$this->hasOption( 'unicode-data-file' ) ) {
$dataFile = 'UnicodeData.txt';
if ( !file_exists( $dataFile ) ) {
$this->fatalError( "Unable to find UnicodeData.txt. Please specify " .
Method __construct
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct() {
parent::__construct();
$this->addDescription( 'Imports images and other media files into the wiki' );
$this->addArg( 'dir', 'Path to the directory containing images to be imported' );
Method doReassignEdits
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function doReassignEdits( &$from, &$to, $updateRC = false, $report = false ) {
$dbw = $this->getPrimaryDB();
$this->beginTransaction( $dbw, __METHOD__ );
$actorNormalization = $this->getServiceContainer()->getActorNormalization();
$fromActorId = $actorNormalization->findActorId( $from, $dbw );