wikimedia/mediawiki-core

View on GitHub
includes/watcheditem/WatchedItemStore.php

Summary

Maintainability
F
1 wk
Test Coverage

File WatchedItemStore.php has 1172 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

use MediaWiki\Cache\LinkBatchFactory;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Deferred\DeferredUpdates;
Severity: Major
Found in includes/watcheditem/WatchedItemStore.php - About 3 days to fix

    WatchedItemStore has 54 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class WatchedItemStore implements WatchedItemStoreInterface {
    
        /**
         * @internal For use by ServiceWiring
         */
    Severity: Major
    Found in includes/watcheditem/WatchedItemStore.php - About 7 hrs to fix

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

          public function resetNotificationTimestamp(
              UserIdentity $user,
              $title,
              $force = '',
              $oldid = 0
      Severity: Major
      Found in includes/watcheditem/WatchedItemStore.php - About 2 hrs to fix

        Function removeWatchBatchForUser has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            public function removeWatchBatchForUser( UserIdentity $user, array $titles ): bool {
                if ( !$user->isRegistered() || $this->readOnlyMode->isReadOnly() ) {
                    return false;
                }
                if ( !$titles ) {
        Severity: Minor
        Found in includes/watcheditem/WatchedItemStore.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 removeWatchBatchForUser has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function removeWatchBatchForUser( UserIdentity $user, array $titles ): bool {
                if ( !$user->isRegistered() || $this->readOnlyMode->isReadOnly() ) {
                    return false;
                }
                if ( !$titles ) {
        Severity: Minor
        Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

          Method updateNotificationTimestamp has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function updateNotificationTimestamp(
                  UserIdentity $editor,
                  $target,
                  $timestamp
              ): array {
          Severity: Minor
          Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

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

                public function setNotificationTimestampsForUser(
                    UserIdentity $user,
                    $timestamp,
                    array $targets = []
                ): bool {
            Severity: Minor
            Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

              Function uncacheAllItemsForUser has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function uncacheAllItemsForUser( UserIdentity $user ) {
                      $userId = $user->getId();
                      foreach ( $this->cacheIndex as $ns => $dbKeyIndex ) {
                          foreach ( $dbKeyIndex as $dbKey => $userIndex ) {
                              if ( array_key_exists( $userId, $userIndex ) ) {
              Severity: Minor
              Found in includes/watcheditem/WatchedItemStore.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 setNotificationTimestampsForUser has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function setNotificationTimestampsForUser(
                      UserIdentity $user,
                      $timestamp,
                      array $targets = []
                  ): bool {
              Severity: Minor
              Found in includes/watcheditem/WatchedItemStore.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 removeExpired has 39 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function removeExpired( int $limit, bool $deleteOrphans = false ): void {
                      $dbr = $this->lbFactory->getReplicaDatabase();
                      $dbw = $this->lbFactory->getPrimaryDatabase();
                      $ticket = $this->lbFactory->getEmptyTransactionTicket( __METHOD__ );
              
              
              Severity: Minor
              Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

                Method getNotificationTimestampsBatch has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function getNotificationTimestampsBatch( UserIdentity $user, array $targets ): array {
                        $timestamps = [];
                        foreach ( $targets as $target ) {
                            $timestamps[$target->getNamespace()][$target->getDBkey()] = false;
                        }
                Severity: Minor
                Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

                  Method fetchWatchedItems has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function fetchWatchedItems(
                          IReadableDatabase $db,
                          UserIdentity $user,
                          array $vars,
                          array $orderBy = [],
                  Severity: Minor
                  Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

                    Method addWatchBatchForUser has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function addWatchBatchForUser(
                            UserIdentity $user,
                            array $targets,
                            ?string $expiry = null
                        ): bool {
                    Severity: Minor
                    Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

                      Method getWatchedItemsForUser has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function getWatchedItemsForUser( UserIdentity $user, array $options = [] ): array {
                              $options += [ 'forWrite' => false ];
                              $vars = [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ];
                              $orderBy = [];
                              if ( $options['forWrite'] ) {
                      Severity: Minor
                      Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

                        Method updateExpiriesAfterMove has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            private function updateExpiriesAfterMove(
                                IDatabase $dbw,
                                array $expiries,
                                int $namespace,
                                string $dbKey
                        Severity: Minor
                        Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

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

                                  ServiceOptions $options,
                                  ILBFactory $lbFactory,
                                  JobQueueGroup $queueGroup,
                                  BagOStuff $stash,
                                  HashBagOStuff $cache,
                          Severity: Major
                          Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

                            Function fetchWatchedItems has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                            Open

                                private function fetchWatchedItems(
                                    IReadableDatabase $db,
                                    UserIdentity $user,
                                    array $vars,
                                    array $orderBy = [],
                            Severity: Minor
                            Found in includes/watcheditem/WatchedItemStore.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 clearUserWatchedItems has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public function clearUserWatchedItems( UserIdentity $user ): bool {
                                    if ( $this->mustClearWatchedItemsUsingJobQueue( $user ) ) {
                                        return false;
                                    }
                            
                            
                            Severity: Minor
                            Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

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

                                  private function getNotificationTimestamp(
                                      UserIdentity $user,
                                      $title,
                                      $item,
                                      $force,
                              Severity: Minor
                              Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

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

                                    public function duplicateEntry( $oldTarget, $newTarget ) {
                                        $dbw = $this->lbFactory->getPrimaryDatabase();
                                        $result = $this->fetchWatchedItemsForPage( $dbw, $oldTarget );
                                        $newNamespace = $newTarget->getNamespace();
                                        $newDBkey = $newTarget->getDBkey();
                                Severity: Minor
                                Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

                                  Method countWatchersMultiple has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      public function countWatchersMultiple( array $targets, array $options = [] ): array {
                                          $linkTargets = array_map( static function ( $target ) {
                                              if ( !$target instanceof LinkTarget ) {
                                                  return new TitleValue( $target->getNamespace(), $target->getDBkey() );
                                              }
                                  Severity: Minor
                                  Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

                                    Method updateOrDeleteExpiries has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                        private function updateOrDeleteExpiries(
                                            IDatabase $dbw,
                                            int $userId,
                                            array $rows,
                                            ?string $expiry = null
                                    Severity: Minor
                                    Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

                                      Method getVisitingWatchersCondition has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                          private function getVisitingWatchersCondition(
                                              IReadableDatabase $db,
                                              array $targetsWithVisitThresholds
                                          ): string {
                                              $missingTargets = [];
                                      Severity: Minor
                                      Found in includes/watcheditem/WatchedItemStore.php - About 1 hr to fix

                                        Function getNotificationTimestamp has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                        Open

                                            private function getNotificationTimestamp(
                                                UserIdentity $user,
                                                $title,
                                                $item,
                                                $force,
                                        Severity: Minor
                                        Found in includes/watcheditem/WatchedItemStore.php - About 55 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 resetNotificationTimestamp has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                        Open

                                            public function resetNotificationTimestamp(
                                                UserIdentity $user,
                                                $title,
                                                $force = '',
                                                $oldid = 0
                                        Severity: Minor
                                        Found in includes/watcheditem/WatchedItemStore.php - About 55 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 addWatchBatchForUser has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                        Open

                                            public function addWatchBatchForUser(
                                                UserIdentity $user,
                                                array $targets,
                                                ?string $expiry = null
                                            ): bool {
                                        Severity: Minor
                                        Found in includes/watcheditem/WatchedItemStore.php - About 55 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 getNotificationTimestampsBatch has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                        Open

                                            public function getNotificationTimestampsBatch( UserIdentity $user, array $targets ): array {
                                                $timestamps = [];
                                                foreach ( $targets as $target ) {
                                                    $timestamps[$target->getNamespace()][$target->getDBkey()] = false;
                                                }
                                        Severity: Minor
                                        Found in includes/watcheditem/WatchedItemStore.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 getNotificationTimestamp has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                        Open

                                                UserIdentity $user,
                                                $title,
                                                $item,
                                                $force,
                                                $oldid
                                        Severity: Minor
                                        Found in includes/watcheditem/WatchedItemStore.php - About 35 mins to fix

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

                                                  IReadableDatabase $db,
                                                  UserIdentity $user,
                                                  array $vars,
                                                  array $orderBy = [],
                                                  $target = null
                                          Severity: Minor
                                          Found in includes/watcheditem/WatchedItemStore.php - About 35 mins to fix

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

                                                public function getWatchedItemsForUser( UserIdentity $user, array $options = [] ): array {
                                                    $options += [ 'forWrite' => false ];
                                                    $vars = [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ];
                                                    $orderBy = [];
                                                    if ( $options['forWrite'] ) {
                                            Severity: Minor
                                            Found in includes/watcheditem/WatchedItemStore.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 $notificationTimestamp;
                                            Severity: Major
                                            Found in includes/watcheditem/WatchedItemStore.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                              return $item->getNotificationTimestamp();
                                              Severity: Major
                                              Found in includes/watcheditem/WatchedItemStore.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                                return false;
                                                Severity: Major
                                                Found in includes/watcheditem/WatchedItemStore.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                          return true;
                                                  Severity: Major
                                                  Found in includes/watcheditem/WatchedItemStore.php - About 30 mins to fix

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

                                                        private function getVisitingWatchersCondition(
                                                            IReadableDatabase $db,
                                                            array $targetsWithVisitThresholds
                                                        ): string {
                                                            $missingTargets = [];
                                                    Severity: Minor
                                                    Found in includes/watcheditem/WatchedItemStore.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 uncacheUser has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                    Open

                                                        private function uncacheUser( UserIdentity $user ) {
                                                            $this->statsFactory->getCounter( 'WatchedItemStore_uncacheUser_total' )
                                                                ->copyToStatsdAt( 'WatchedItemStore.uncacheUser' )
                                                                ->increment();
                                                            $uncacheUserItemsTotal = $this->statsFactory->getCounter( 'WatchedItemStore_uncacheUser_items_total' )
                                                    Severity: Minor
                                                    Found in includes/watcheditem/WatchedItemStore.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 duplicateEntry has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                    Open

                                                        public function duplicateEntry( $oldTarget, $newTarget ) {
                                                            $dbw = $this->lbFactory->getPrimaryDatabase();
                                                            $result = $this->fetchWatchedItemsForPage( $dbw, $oldTarget );
                                                            $newNamespace = $newTarget->getNamespace();
                                                            $newDBkey = $newTarget->getDBkey();
                                                    Severity: Minor
                                                    Found in includes/watcheditem/WatchedItemStore.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

                                                    There are no issues that match your filters.

                                                    Category
                                                    Status