wikimedia/mediawiki-extensions-MobileFrontend

View on GitHub

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;
                } );
Severity: Major
Found in src/mobile.editor.overlay/SourceEditorOverlay.js and 1 other location - About 1 hr to fix
src/mobile.editor.overlay/VisualEditorOverlay.js on lines 318..322

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

Further Reading

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;
Severity: Minor
Found in src/mobile.startup/PageHTMLParser.js - About 1 hr to fix

    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,
    Severity: Minor
    Found in src/mobile.editor.overlay/SourceEditorOverlay.js - About 1 hr to fix

      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 ) {
      Severity: Minor
      Found in includes/MobileContext.php - About 1 hr to fix

        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',
        Severity: Minor
        Found in src/mobile.startup/time.js - About 1 hr to fix

          Function EditorOverlayBase has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function EditorOverlayBase( params ) {
              const
                  options = util.extend(
                      true,
                      {
          Severity: Minor
          Found in src/mobile.editor.overlay/EditorOverlayBase.js - About 1 hr to fix

            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' ),
            Severity: Minor
            Found in src/mobile.editor.overlay/EditorGateway.js - About 1 hr to fix

              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', [
              Severity: Minor
              Found in includes/specials/SpecialMobileEditWatchlist.php - About 1 hr to fix

                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',
                Severity: Minor
                Found in src/mobile.startup/Drawer.js - About 1 hr to fix

                  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' ),
                  Severity: Minor
                  Found in src/mobile.startup/search/SearchOverlay.js - About 1 hr to fix

                    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( {
                    Severity: Minor
                    Found in src/mobile.editor.overlay/VisualEditorOverlay.js - About 1 hr to fix

                      Function findChildInSectionLead has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          findChildInSectionLead( sectionIndex, selector ) {
                              let $heading, $nextHeading;
                      
                              const headingSelector = HEADING_SELECTOR;
                      
                      
                      Severity: Minor
                      Found in src/mobile.startup/PageHTMLParser.js - About 1 hr to fix

                        Function onSaveComplete has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            onSaveComplete: function ( newRevId, redirectUrl, tempUserCreated ) {
                                const
                                    self = this;
                        
                                this.saved = true;
                        Severity: Minor
                        Found in src/mobile.editor.overlay/EditorOverlayBase.js - About 1 hr to fix

                          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 ),
                          Severity: Minor
                          Found in src/mobile.startup/search/SearchOverlay.js - About 1 hr to fix

                            Function onSaveBegin has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                onSaveBegin: function () {
                                    const self = this,
                                        options = {
                                            summary: this.getEditSummary()
                                        };
                            Severity: Minor
                            Found in src/mobile.editor.overlay/SourceEditorOverlay.js - About 1 hr to fix

                              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() ) {
                              Severity: Minor
                              Found in includes/MobileFrontendHooks.php - About 1 hr to fix

                                Function exports has 9 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                    action,
                                    promoCampaign,
                                    mwMessage,
                                    mwUtil,
                                    toast,
                                Severity: Major
                                Found in src/mobile.startup/amcOutreach/amcOutreachDrawer.js - About 1 hr to fix

                                  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' );
                                  Severity: Minor
                                  Found in includes/MobileFrontendHooks.php - About 1 hr to fix

                                    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 ) ) {
                                    Severity: Minor
                                    Found in src/mobile.init/lazyLoadedImages.js - About 1 hr to fix

                                      Function getStructuredLanguages has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                          getStructuredLanguages: function (
                                              languages,
                                              variants,
                                              frequentlyUsedLanguages,
                                              showSuggestedLanguages,
                                      Severity: Minor
                                      Found in src/mobile.languages.structured/util.js - About 1 hr to fix

                                      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

                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language