Showing 183 of 183 total issues
Identical blocks of code found in 2 locations. Consider refactoring. Open
newOverlay.getLoadingPromise().then( function () {
self.switching = true;
self.overlayManager.replaceCurrent( newOverlay );
self.switching = false;
} );
- 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 60.
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
Function getLanguages
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
getLanguages( pageTitle ) {
const mapLinkToLanguageObj = ( node ) => {
const DELIMITER = ' – ';
// Name of language (e.g. עברית for Hebrew)
const autonym = node.textContent;
Function SourceEditorOverlay
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
function SourceEditorOverlay( options, dataPromise ) {
this.isFirefox = /firefox/i.test( window.navigator.userAgent );
this.gateway = new EditorGateway( {
api: options.api,
title: options.title,
Method doToggling
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function doToggling() {
// make sure viewChange is set
$this->shouldDisplayMobileView();
if ( !$this->viewChange ) {
Function getLastModifiedMessage
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
function getLastModifiedMessage( ts, username, gender, historyUrl ) {
const linkAll = typeof historyUrl === 'undefined',
keys = {
seconds: 'mobile-frontend-last-modified-with-user-seconds',
minutes: 'mobile-frontend-last-modified-with-user-minutes',
Function EditorOverlayBase
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
function EditorOverlayBase( params ) {
const
options = util.extend(
true,
{
Function saveContent
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
function saveContent() {
const apiOptions = {
action: 'edit',
errorformat: 'html',
errorlang: mw.config.get( 'wgUserLanguage' ),
Method getLineHtml
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getLineHtml( MobilePage $mp ) {
$thumb = $mp->getSmallThumbnailHtml( true );
$title = $mp->getTitle();
if ( !$thumb ) {
$thumb = Html::rawElement( 'div', [
Function Drawer
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
function Drawer( props ) {
this.drawerClassName = props.className || '';
this.collapseIcon = new IconButton( {
icon: 'expand',
additionalClassNames: 'cancel',
Function postRender
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
postRender() {
const self = this,
searchResults = new SearchResultsView( {
searchContentLabel: mw.msg( 'mobile-frontend-search-content' ),
noResultsMsg: mw.msg( 'mobile-frontend-search-no-results' ),
Function switchToSourceEditor
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
switchToSourceEditor: function ( dataPromise ) {
const self = this,
SourceEditorOverlay = this.SourceEditorOverlay,
options = this.getOptionsForSwitch();
this.log( {
Function findChildInSectionLead
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
findChildInSectionLead( sectionIndex, selector ) {
let $heading, $nextHeading;
const headingSelector = HEADING_SELECTOR;
Function onSaveComplete
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
onSaveComplete: function ( newRevId, redirectUrl, tempUserCreated ) {
const
self = this;
this.saved = true;
Function SearchOverlay
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
function SearchOverlay( params ) {
const header = searchHeader(
params.placeholderMsg,
params.action || mw.config.get( 'wgScript' ),
( query ) => this.performSearch( query ),
Function onSaveBegin
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
onSaveBegin: function () {
const self = this,
options = {
summary: this.getEditSummary()
};
Method onRequestContextCreateSkin
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function onRequestContextCreateSkin( $context, &$skin ) {
$mobileContext = $this->mobileContext;
$mobileContext->doToggling();
if ( !$mobileContext->shouldDisplayMobileView() ) {
Function exports
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
action,
promoCampaign,
mwMessage,
mwUtil,
toast,
Method getResourceLoaderMFConfigVars
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getResourceLoaderMFConfigVars() {
$vars = [];
$config = MediaWikiServices::getInstance()->getService( 'MobileFrontend.Config' );
$mfScriptPath = $config->get( 'MFScriptPath' );
$pageProps = $config->get( 'MFQueryPropModules' );
Function init
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function init( $container ) {
// T360781 - since this is invoked via hook, the value of $container is not guaranteed.
// If undefined, return early since no further work can be done on $container.
if ( !( $container[ 0 ] instanceof HTMLElement ) ) {
Function getStructuredLanguages
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
getStructuredLanguages: function (
languages,
variants,
frequentlyUsedLanguages,
showSuggestedLanguages,
- 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"