File WatchedItemStore.php
has 1176 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace MediaWiki\Watchlist;
use DateInterval;
WatchedItemStore
has 54 functions (exceeds 20 allowed). Consider refactoring. Open
class WatchedItemStore implements WatchedItemStoreInterface {
/**
* @internal For use by ServiceWiring
*/
Method resetNotificationTimestamp
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function resetNotificationTimestamp(
UserIdentity $user,
$title,
$force = '',
$oldid = 0
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 ) {
- Read upRead up
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 ) {
Method updateNotificationTimestamp
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function updateNotificationTimestamp(
UserIdentity $editor,
$target,
$timestamp
): array {
Method setNotificationTimestampsForUser
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setNotificationTimestampsForUser(
UserIdentity $user,
$timestamp,
array $targets = []
): bool {
Function setNotificationTimestampsForUser
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function setNotificationTimestampsForUser(
UserIdentity $user,
$timestamp,
array $targets = []
): bool {
- Read upRead up
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 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 ) ) {
- Read upRead up
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__ );
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;
}
Method fetchWatchedItems
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function fetchWatchedItems(
IReadableDatabase $db,
UserIdentity $user,
array $vars,
array $orderBy = [],
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'] ) {
Method addWatchBatchForUser
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addWatchBatchForUser(
UserIdentity $user,
array $targets,
?string $expiry = null
): bool {
Method updateExpiriesAfterMove
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function updateExpiriesAfterMove(
IDatabase $dbw,
array $expiries,
int $namespace,
string $dbKey
Method __construct
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
ServiceOptions $options,
ILBFactory $lbFactory,
JobQueueGroup $queueGroup,
BagOStuff $stash,
HashBagOStuff $cache,
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 = [],
- Read upRead up
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;
}
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();
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() );
}
Method getNotificationTimestamp
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getNotificationTimestamp(
UserIdentity $user,
$title,
$item,
$force,
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
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 {
- Read upRead up
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
- Read upRead up
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;
}
- Read upRead up
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 getNotificationTimestamp
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function getNotificationTimestamp(
UserIdentity $user,
$title,
$item,
$force,
- Read upRead up
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 fetchWatchedItems
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
IReadableDatabase $db,
UserIdentity $user,
array $vars,
array $orderBy = [],
$target = null
Method getNotificationTimestamp
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
UserIdentity $user,
$title,
$item,
$force,
$oldid
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'] ) {
- Read upRead up
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;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return $item->getNotificationTimestamp();
Avoid too many return
statements within this method. Open
return false;
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();
- Read upRead up
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' )
- Read upRead up
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 getVisitingWatchersCondition
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function getVisitingWatchersCondition(
IReadableDatabase $db,
array $targetsWithVisitThresholds
): string {
$missingTargets = [];
- Read upRead up
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"