wikimedia/mediawiki-extensions-MobileFrontend

View on GitHub

Showing 191 of 191 total issues

Method renderFeedItemHtml has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function renderFeedItemHtml( array $options ): void {
        $output = $this->getOutput();
        $user = $this->getUser();
        $lang = $this->getLanguage();

Severity: Major
Found in includes/specials/MobileSpecialPageFeed.php - 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

              $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 104..121

      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

              $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 157..174

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

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

        Function postRender has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            postRender: function () {
                var
                    $img,
                    $el = this.$el,
                    $spinner = icons.spinner().$el,
        Severity: Major
        Found in src/mobile.mediaViewer/ImageCarousel.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 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

              Method executeViewEditWatchlist has 55 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 getContent has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    getContent: function () {
                        var options,
                            self = this;
                
                        function resolve() {
                Severity: Major
                Found in src/mobile.editor.overlay/EditorGateway.js - 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

                    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

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

                      function amcOutreachDrawer(
                          action,
                          promoCampaign,
                          mwMessage,
                          mwUtil,
                      Severity: Major
                      Found in src/mobile.startup/amcOutreach/amcOutreachDrawer.js - 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

                          Method getLineHtml has 50 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 2 hrs to fix

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

                                createAnonWarning: function ( options ) {
                                    var $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

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

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

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

                                    public function getMobileUrl( $url, $forceHttps = false ) {
                                        if ( $this->shouldDisplayMobileView() ) {
                                            $subdomainTokenReplacement = null;
                                            $hookRunner = new HookRunner( MediaWikiServices::getInstance()->getHookContainer() );
                                            if ( $hookRunner->onGetMobileUrl( $subdomainTokenReplacement, $this ) ) {
                                Severity: Minor
                                Found in includes/MobileContext.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 onBeforePageDisplay has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public function onBeforePageDisplay( $out, $skin ): void {
                                        $context = MobileContext::singleton();
                                        $services = MediaWikiServices::getInstance();
                                        $config = $services->getService( 'MobileFrontend.Config' );
                                        $mfEnableXAnalyticsLogging = $config->get( 'MFEnableXAnalyticsLogging' );
                                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

                                Severity
                                Category
                                Status
                                Source
                                Language