wikimedia/mediawiki-core

View on GitHub
includes/specials/SpecialWatchlist.php

Summary

Maintainability
F
6 days
Test Coverage

File SpecialWatchlist.php has 750 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Implements Special:Watchlist
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Major
Found in includes/specials/SpecialWatchlist.php - About 1 day to fix

    Method doHeader has 148 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function doHeader( $opts, $numRows ) {
            $user = $this->getUser();
            $out = $this->getOutput();
            $skin = $this->getSkin();
            // For legacy skins render the tabs in the subtitle
    Severity: Major
    Found in includes/specials/SpecialWatchlist.php - About 5 hrs to fix

      Method registerFilters has 126 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function registerFilters() {
              parent::registerFilters();
      
              // legacy 'extended' filter
              $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [
      Severity: Major
      Found in includes/specials/SpecialWatchlist.php - About 5 hrs to fix

        Method outputChangesList has 83 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function outputChangesList( $rows, $opts ) {
                $dbr = $this->getDB();
                $user = $this->getUser();
                $output = $this->getOutput();
        
        
        Severity: Major
        Found in includes/specials/SpecialWatchlist.php - About 3 hrs to fix

          Method doMainQuery has 76 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function doMainQuery( $tables, $fields, $conds, $query_options,
                  $join_conds, FormOptions $opts
              ) {
                  $dbr = $this->getDB();
                  $user = $this->getUser();
          Severity: Major
          Found in includes/specials/SpecialWatchlist.php - About 3 hrs to fix

            SpecialWatchlist has 25 functions (exceeds 20 allowed). Consider refactoring.
            Open

            class SpecialWatchlist extends ChangesListSpecialPage {
                /** @var array */
                public const WATCHLIST_TAB_PATHS = [
                    'Special:Watchlist',
                    'Special:EditWatchlist',
            Severity: Minor
            Found in includes/specials/SpecialWatchlist.php - About 2 hrs to fix

              Function outputChangesList has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function outputChangesList( $rows, $opts ) {
                      $dbr = $this->getDB();
                      $user = $this->getUser();
                      $output = $this->getOutput();
              
              
              Severity: Minor
              Found in includes/specials/SpecialWatchlist.php - About 2 hrs 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

              Method setTopText has 44 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function setTopText( FormOptions $opts ) {
                      $nondefaults = $opts->getChangedValues();
                      $form = '';
                      $user = $this->getUser();
              
              
              Severity: Minor
              Found in includes/specials/SpecialWatchlist.php - About 1 hr to fix

                Method execute has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function execute( $subpage ) {
                        $user = $this->getUser();
                        if (
                            // Anons don't get a watchlist
                            !$user->isRegistered()
                Severity: Minor
                Found in includes/specials/SpecialWatchlist.php - About 1 hr to fix

                  Function execute has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function execute( $subpage ) {
                          $user = $this->getUser();
                          if (
                              // Anons don't get a watchlist
                              !$user->isRegistered()
                  Severity: Minor
                  Found in includes/specials/SpecialWatchlist.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

                  Method cutoffselector has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function cutoffselector( $options ) {
                          $selected = (float)$options['days'];
                          $maxDays = $this->getConfig()->get( MainConfigNames::RCMaxAge ) / ( 3600 * 24 );
                          if ( $selected <= 0 ) {
                              $selected = $maxDays;
                  Severity: Minor
                  Found in includes/specials/SpecialWatchlist.php - About 1 hr to fix

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

                        public function setTopText( FormOptions $opts ) {
                            $nondefaults = $opts->getChangedValues();
                            $form = '';
                            $user = $this->getUser();
                    
                    
                    Severity: Minor
                    Found in includes/specials/SpecialWatchlist.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

                    Method doMainQuery has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        protected function doMainQuery( $tables, $fields, $conds, $query_options,
                            $join_conds, FormOptions $opts
                    Severity: Minor
                    Found in includes/specials/SpecialWatchlist.php - About 45 mins to fix

                      Function registerFilters has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                          protected function registerFilters() {
                              parent::registerFilters();
                      
                              // legacy 'extended' filter
                              $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [
                      Severity: Minor
                      Found in includes/specials/SpecialWatchlist.php - About 45 mins 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

                      Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                              WatchedItemStoreInterface $watchedItemStore,
                              WatchlistManager $watchlistManager,
                              UserOptionsLookup $userOptionsLookup,
                              ChangeTagsStore $changeTagsStore,
                              UserIdentityUtils $userIdentityUtils,
                      Severity: Minor
                      Found in includes/specials/SpecialWatchlist.php - About 45 mins to fix

                        Method showHideCheck has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
                        Severity: Minor
                        Found in includes/specials/SpecialWatchlist.php - About 35 mins to fix

                          Function doMainQuery has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              protected function doMainQuery( $tables, $fields, $conds, $query_options,
                                  $join_conds, FormOptions $opts
                              ) {
                                  $dbr = $this->getDB();
                                  $user = $this->getUser();
                          Severity: Minor
                          Found in includes/specials/SpecialWatchlist.php - About 35 mins 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

                          Avoid too many return statements within this method.
                          Open

                                          return $path;
                          Severity: Major
                          Found in includes/specials/SpecialWatchlist.php - About 30 mins to fix

                            Function fetchOptionsFromRequest has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                                protected function fetchOptionsFromRequest( $opts ) {
                                    static $compatibilityMap = [
                                        'hideMinor' => 'hideminor',
                                        'hideBots' => 'hidebots',
                                        'hideAnons' => 'hideanons',
                            Severity: Minor
                            Found in includes/specials/SpecialWatchlist.php - About 25 mins 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 doHeader has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public function doHeader( $opts, $numRows ) {
                                    $user = $this->getUser();
                                    $out = $this->getOutput();
                                    $skin = $this->getSkin();
                                    // For legacy skins render the tabs in the subtitle
                            Severity: Minor
                            Found in includes/specials/SpecialWatchlist.php - About 25 mins 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

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

                                    if ( $this->isStructuredFilterUiEnabled() ) {
                                        $rcfilterContainer = Html::element(
                                            'div',
                                            [ 'class' => 'mw-rcfilters-container' ]
                                        );
                            Severity: Major
                            Found in includes/specials/SpecialWatchlist.php and 1 other location - About 2 hrs to fix
                            includes/specials/SpecialRecentChanges.php on lines 697..725

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

                            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

                                    $namespaceForm .= Html::rawElement( 'label', [
                                        'class' => 'mw-input-with-label', 'title' => $this->msg( 'tooltip-invert' )->text(),
                                    ], Html::element( 'input', [
                                        'type' => 'checkbox', 'name' => 'invert', 'value' => '1', 'checked' => $opts['invert'],
                                    ] ) . '&nbsp;' . $this->msg( 'invert' )->escaped() ) . "\n";
                            Severity: Minor
                            Found in includes/specials/SpecialWatchlist.php and 1 other location - About 45 mins to fix
                            includes/specials/SpecialWatchlist.php on lines 808..812

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

                            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

                                    $namespaceForm .= Html::rawElement( 'label', [
                                        'class' => 'mw-input-with-label', 'title' => $this->msg( 'tooltip-namespace_association' )->text(),
                                    ], Html::element( 'input', [
                                        'type' => 'checkbox', 'name' => 'associated', 'value' => '1', 'checked' => $opts['associated'],
                                    ] ) . '&nbsp;' . $this->msg( 'namespace_association' )->escaped() ) . "\n";
                            Severity: Minor
                            Found in includes/specials/SpecialWatchlist.php and 1 other location - About 45 mins to fix
                            includes/specials/SpecialWatchlist.php on lines 803..807

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

                            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

                            There are no issues that match your filters.

                            Category
                            Status