wikimedia/mediawiki-extensions-MobileFrontend

View on GitHub

Showing 183 of 183 total issues

Method domParseMobile has 61 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function domParseMobile( OutputPage $out, $html = '' ) {
        $services = MediaWikiServices::getInstance();
        /** @var FeaturesManager $featuresManager */
        $featuresManager = $services->getService( 'MobileFrontend.FeaturesManager' );
        /** @var MobileContext $context */
Severity: Major
Found in includes/ExtMobileFrontend.php - About 2 hrs to fix

    Function editorLoadingOverlay has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    module.exports = function editorLoadingOverlay( afterShow, afterHide, loadBasicEditor ) {
        let timeout;
        const
            $fakeToolbar = fakeToolbar(),
            $loadBasicWrapper = $( '<div>' ).addClass( 've-loadbasiceditor' ),
    Severity: Major
    Found in src/mobile.init/editorLoadingOverlay.js - About 2 hrs to fix

      Method detectMobileDevice has 61 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function detectMobileDevice( $userAgent ) {
              $patterns = [
                  'mobi',
                  '240x240',
                  '240x320',
      Severity: Major
      Found in includes/Devices/UADeviceDetector.php - About 2 hrs to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                $layout = new OOUI\FieldLayout(
                    $amcToggle,
                    [
                        'label' => new OOUI\LabelWidget( [
                            'input' => $amcToggle,
        Severity: Major
        Found in includes/specials/SpecialMobileOptions.php and 1 other location - About 2 hrs to fix
        includes/specials/SpecialMobileOptions.php on lines 171..188

        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 130.

        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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                $userPreferences = new OOUI\FieldLayout(
                    $spacer,
                    [
                        'label' => new OOUI\LabelWidget( [
                            'input' => $spacer,
        Severity: Major
        Found in includes/specials/SpecialMobileOptions.php and 1 other location - About 2 hrs to fix
        includes/specials/SpecialMobileOptions.php on lines 118..135

        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 130.

        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 postRender has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            postRender: function () {
                let
                    $img;
                const
                    $el = this.$el,
        Severity: Major
        Found in src/mobile.mediaViewer/ImageCarousel.js - About 2 hrs to fix

          Function template has 55 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              get template() {
                  return util.template( `
          <div class="block-message block-message-container">
            <div class="block-message-icon"></div>
            <div class="block-message-info">
          Severity: Major
          Found in src/mobile.editor.overlay/BlockMessageDetails.js - About 2 hrs to fix

            Function getStructuredLanguages has 55 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                getStructuredLanguages: function (
                    languages,
                    variants,
                    frequentlyUsedLanguages,
                    showSuggestedLanguages,
            Severity: Major
            Found in src/mobile.languages.structured/util.js - About 2 hrs to fix

              Function getContent has 54 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  getContent: function () {
                      let options;
              
                      const self = this;
              
              
              Severity: Major
              Found in src/mobile.editor.overlay/EditorGateway.js - About 2 hrs to fix

                Method executeViewEditWatchlist has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function executeViewEditWatchlist() {
                        $ns = NS_MAIN;
                        $images = [];
                
                        $watchlist = $this->getWatchlistInfo();
                Severity: Major
                Found in includes/specials/SpecialMobileEditWatchlist.php - About 2 hrs to fix

                  Function parseBlockInfo has 52 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  module.exports = function parseBlockInfo( blockinfo ) {
                      const blockInfo = {
                          partial: blockinfo.blockpartial || false,
                          noCreateAccount: blockinfo.blocknocreate || false,
                          anonOnly: blockinfo.blockanononly === undefined ? true : blockinfo.blockanononly,
                  Severity: Major
                  Found in src/mobile.editor.overlay/parseBlockInfo.js - About 2 hrs to fix

                    Function amcOutreachDrawer has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    module.exports = function amcOutreachDrawer(
                        action,
                        promoCampaign,
                        mwMessage,
                        mwUtil,
                    Severity: Major
                    Found in src/mobile.startup/amcOutreach/amcOutreachDrawer.js - About 2 hrs to fix

                      Method submitSettingsForm has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private function submitSettingsForm() {
                              $request = $this->getRequest();
                              $user = $this->getUser();
                      
                              if ( $user->isRegistered() && !$user->matchEditToken( $request->getVal( 'token' ) ) ) {
                      Severity: Major
                      Found in includes/specials/SpecialMobileOptions.php - About 2 hrs to fix

                        Method doRewriteImagesForLazyLoading has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            private function doRewriteImagesForLazyLoading( $el, ?DOMDocument $doc ) {
                                if ( $doc === null ) {
                                    return;
                                }
                                $lazyLoadSkipSmallImages = $this->skipSmall;
                        Severity: Minor
                        Found in includes/Transforms/LazyImageTransform.php - About 2 hrs to fix

                          Function referenceDrawer has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          function referenceDrawer( props ) {
                              const errorIcon = props.error ? new IconButton( {
                                  name: 'error',
                                  isSmall: true
                              } ).$el : null;
                          Severity: Minor
                          Found in src/mobile.startup/references/references.js - About 2 hrs to fix

                            Function createAnonWarning has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                createAnonWarning: function ( options ) {
                                    const $actions = $( '<div>' ).addClass( 'actions' ),
                                        // Use MediaWiki ResourceLoader require(), not Webpack require()
                                        contLangMessages = (
                            
                            
                            Severity: Minor
                            Found in src/mobile.editor.overlay/EditorOverlayBase.js - About 1 hr to fix

                              Function onBeforePageDisplay has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function onBeforePageDisplay( $out, $skin ): void {
                                      $context = $this->mobileContext;
                                      $mfEnableXAnalyticsLogging = $this->config->get( 'MFEnableXAnalyticsLogging' );
                                      $mfNoIndexPages = $this->config->get( 'MFNoindexPages' );
                                      $isCanonicalLinkHandledByCore = $this->config->get( 'EnableCanonicalServerLink' );
                              Severity: Minor
                              Found in includes/MobileFrontendHooks.php - 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

                              Function findChildInSectionLead has a Cognitive Complexity of 15 (exceeds 5 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

                              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 getTopHeadings has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  private function getTopHeadings( DOMElement $doc ): array {
                                      $headings = [];
                              
                                      foreach ( $this->topHeadingTags as $tagName ) {
                                          $allTags = DOMCompat::querySelectorAll( $doc, $tagName );
                              Severity: Minor
                              Found in includes/Transforms/MakeSectionsTransform.php - 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

                              Function _switchToVisualEditor has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  _switchToVisualEditor: function ( wikitext ) {
                                      const self = this;
                                      this.log( {
                                          action: 'abort',
                                          type: 'switchnochange',
                              Severity: Minor
                              Found in src/mobile.editor.overlay/SourceEditorOverlay.js - About 1 hr to fix
                                Severity
                                Category
                                Status
                                Source
                                Language