File RevisionStore.php
has 2010 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
RevisionStore
has 72 functions (exceeds 20 allowed). Consider refactoring. Open
class RevisionStore implements RevisionFactory, RevisionLookup, LoggerAwareInterface {
use LegacyArticleIdAccess;
public const ROW_CACHE_KEY = 'revision-row-1.29';
Method newRevisionsFromBatch
has 156 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function newRevisionsFromBatch(
$rows,
array $options = [],
$queryFlags = 0,
PageIdentity $page = null
Function getSlotRowsForBatch
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
private function getSlotRowsForBatch(
$rowsOrIds,
array $options = [],
$queryFlags = 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 newRevisionsFromBatch
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
public function newRevisionsFromBatch(
$rows,
array $options = [],
$queryFlags = 0,
PageIdentity $page = null
- 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 newRevisionFromRowAndSlots
has 87 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function newRevisionFromRowAndSlots(
stdClass $row,
$slots,
int $queryFlags = 0,
?PageIdentity $page = null,
Method getSlotRowsForBatch
has 75 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getSlotRowsForBatch(
$rowsOrIds,
array $options = [],
$queryFlags = 0
) {
Method insertRevisionOn
has 74 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function insertRevisionOn( RevisionRecord $rev, IDatabase $dbw ) {
// TODO: pass in a DBTransactionContext instead of a database connection.
$this->checkDatabaseDomain( $dbw );
$slotRoles = $rev->getSlotRoles();
Method insertRevisionRowOn
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function insertRevisionRowOn(
IDatabase $dbw,
RevisionRecord $rev,
$parentId
) {
Function constructSlotRecords
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
private function constructSlotRecords(
$revId,
$slotRows,
$queryFlags,
PageIdentity $page,
- 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 getQueryInfo
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getQueryInfo( $options = [] ) {
$ret = [
'tables' => [],
'fields' => [],
'joins' => [],
Method loadSlotContent
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function loadSlotContent(
SlotRecord $slot,
?string $blobData = null,
?string $blobFlags = null,
?string $blobFormat = null,
Function loadSlotContent
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
private function loadSlotContent(
SlotRecord $slot,
?string $blobData = null,
?string $blobFlags = null,
?string $blobFormat = null,
- 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 getKnownCurrentRevision
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getKnownCurrentRevision( PageIdentity $page, $revId = 0 ) {
$db = $this->getDBConnection( DB_REPLICA );
$revIdPassed = $revId;
$pageId = $this->getArticleId( $page );
if ( !$pageId ) {
Method ensureRevisionRowMatchesPage
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function ensureRevisionRowMatchesPage( $row, PageIdentity $page, $context = [] ) {
$revId = (int)( $row->rev_id ?? 0 );
$revPageId = (int)( $row->rev_page ?? 0 ); // XXX: also check $row->page_id?
$expectedPageId = $page->getId( $this->wikiId );
// Avoid fatal error when the Title's ID changed, T246720
Function newRevisionFromRowAndSlots
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function newRevisionFromRowAndSlots(
stdClass $row,
$slots,
int $queryFlags = 0,
?PageIdentity $page = null,
- 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 getRelativeRevision
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getRelativeRevision( RevisionRecord $rev, $flags, $dir ) {
$op = $dir === 'next' ? '>' : '<';
$sort = $dir === 'next' ? 'ASC' : 'DESC';
$revisionIdValue = $rev->getId( $this->wikiId );
Method __construct
has 14 arguments (exceeds 4 allowed). Consider refactoring. Open
ILoadBalancer $loadBalancer,
SqlBlobStore $blobStore,
WANObjectCache $cache,
BagOStuff $localCache,
CommentStore $commentStore,
Method constructSlotRecords
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function constructSlotRecords(
$revId,
$slotRows,
$queryFlags,
PageIdentity $page,
Method getAuthorsBetween
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getAuthorsBetween(
$pageId,
RevisionRecord $old = null,
RevisionRecord $new = null,
Authority $performer = null,
Method newRevisionFromArchiveRowAndSlots
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function newRevisionFromArchiveRowAndSlots(
stdClass $row,
$slots,
int $queryFlags = 0,
?PageIdentity $page = null,
Function getPage
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private function getPage( ?int $pageId, ?int $revId, int $queryFlags = IDBAccessObject::READ_NORMAL ) {
if ( !$pageId && !$revId ) {
throw new InvalidArgumentException( '$pageId and $revId cannot both be 0 or null' );
}
- 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 insertRevisionRowOn
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private function insertRevisionRowOn(
IDatabase $dbw,
RevisionRecord $rev,
$parentId
) {
- 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 ensureRevisionRowMatchesPage
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private function ensureRevisionRowMatchesPage( $row, PageIdentity $page, $context = [] ) {
$revId = (int)( $row->rev_id ?? 0 );
$revPageId = (int)( $row->rev_page ?? 0 ); // XXX: also check $row->page_id?
$expectedPageId = $page->getId( $this->wikiId );
// Avoid fatal error when the Title's ID changed, T246720
- 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 updateSlotsOn
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function updateSlotsOn(
RevisionRecord $revision,
RevisionSlotsUpdate $revisionSlotsUpdate,
IDatabase $dbw
): array {
Method getPage
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getPage( ?int $pageId, ?int $revId, int $queryFlags = IDBAccessObject::READ_NORMAL ) {
if ( !$pageId && !$revId ) {
throw new InvalidArgumentException( '$pageId and $revId cannot both be 0 or null' );
}
Method newNullRevision
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function newNullRevision(
IDatabase $dbw,
PageIdentity $page,
CommentStoreComment $comment,
$minor,
Method getSlotsQueryInfo
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getSlotsQueryInfo( $options = [] ) {
$ret = [
'tables' => [],
'fields' => [],
'joins' => [],
Method insertRevisionInternal
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function insertRevisionInternal(
RevisionRecord $rev,
IDatabase $dbw,
UserIdentity $user,
CommentStoreComment $comment,
Function getContentBlobsForBatch
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function getContentBlobsForBatch(
$rowsOrIds,
$slots = null,
$queryFlags = 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
Method loadSlotRecords
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function loadSlotRecords( $revId, $queryFlags, PageIdentity $page ) {
// TODO: Find a way to add NS_MODULE from Scribunto here
if ( $page->getNamespace() !== NS_TEMPLATE ) {
$res = $this->loadSlotRecordsFromDb( $revId, $queryFlags, $page );
return $this->constructSlotRecords( $revId, $res, $queryFlags, $page );
Function getKnownCurrentRevision
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function getKnownCurrentRevision( PageIdentity $page, $revId = 0 ) {
$db = $this->getDBConnection( DB_REPLICA );
$revIdPassed = $revId;
$pageId = $this->getArticleId( $page );
if ( !$pageId ) {
- 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 newRevisionFromArchiveRowAndSlots
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function newRevisionFromArchiveRowAndSlots(
stdClass $row,
$slots,
int $queryFlags = 0,
?PageIdentity $page = null,
- 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 loadSlotRecordsFromDb
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function loadSlotRecordsFromDb( $revId, $queryFlags, PageIdentity $page ): array {
$revQuery = $this->getSlotsQueryInfo( [ 'content' ] );
[ $dbMode, $dbOptions ] = DBAccessObjectUtils::getDBOptions( $queryFlags );
$db = $this->getDBConnection( $dbMode );
Method getArchiveQueryInfo
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getArchiveQueryInfo() {
$commentQuery = $this->commentStore->getJoin( 'ar_comment' );
$ret = [
'tables' => [
'archive',
Method getRevisionIdsBetween
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getRevisionIdsBetween(
int $pageId,
RevisionRecord $old = null,
RevisionRecord $new = null,
?int $max = null,
Method countRevisionsBetween
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function countRevisionsBetween(
$pageId,
RevisionRecord $old = null,
RevisionRecord $new = null,
$max = null,
Function getRelativeRevision
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function getRelativeRevision( RevisionRecord $rev, $flags, $dir ) {
$op = $dir === 'next' ? '>' : '<';
$sort = $dir === 'next' ? 'ASC' : 'DESC';
$revisionIdValue = $rev->getId( $this->wikiId );
- 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 insertRevisionInternal
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
RevisionRecord $rev,
IDatabase $dbw,
UserIdentity $user,
CommentStoreComment $comment,
PageIdentity $page,
Method getRevisionIdsBetween
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
int $pageId,
RevisionRecord $old = null,
RevisionRecord $new = null,
?int $max = null,
$options = [],
Method countAuthorsBetween
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
$pageId,
RevisionRecord $old = null,
RevisionRecord $new = null,
Authority $performer = null,
$max = null,
Method getAuthorsBetween
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
$pageId,
RevisionRecord $old = null,
RevisionRecord $new = null,
Authority $performer = null,
$max = null,
Method newNullRevision
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
IDatabase $dbw,
PageIdentity $page,
CommentStoreComment $comment,
$minor,
UserIdentity $user
Method newRevisionFromRowAndSlots
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
stdClass $row,
$slots,
int $queryFlags = 0,
?PageIdentity $page = null,
bool $fromCache = false
Method countRevisionsBetween
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
$pageId,
RevisionRecord $old = null,
RevisionRecord $new = null,
$max = null,
$options = []
Method insertSlotOn
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
IDatabase $dbw,
$revisionId,
SlotRecord $protoSlot,
PageIdentity $page,
array $blobHints = []
Method loadSlotContent
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
SlotRecord $slot,
?string $blobData = null,
?string $blobFlags = null,
?string $blobFormat = null,
int $queryFlags = 0
Method constructSlotRecords
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
$revId,
$slotRows,
$queryFlags,
PageIdentity $page,
$slotContents = null
Method newRevisionFromArchiveRowAndSlots
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
stdClass $row,
$slots,
int $queryFlags = 0,
?PageIdentity $page = null,
array $overrides = []
Method loadRevisionFromConds
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
IDatabase $db,
array $conditions,
int $flags = IDBAccessObject::READ_NORMAL,
PageIdentity $page = null,
array $options = []
Function getRevisionLimitConditions
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function getRevisionLimitConditions(
ISQLPlatform $dbr,
RevisionRecord $old = null,
RevisionRecord $new = null,
$options = []
- 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 getAuthorsBetween
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getAuthorsBetween(
$pageId,
RevisionRecord $old = null,
RevisionRecord $new = null,
Authority $performer = null,
- 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 null;
Avoid too many return
statements within this method. Open
return $newRevisionRecord(
$row,
new RevisionSlots(
$this->constructSlotRecords(
$row->$revIdField,
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return $this->getRevisionById( intval( $revId ), $flags );
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $result;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return $result;
Function getRevisionIdsBetween
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getRevisionIdsBetween(
int $pageId,
RevisionRecord $old = null,
RevisionRecord $new = null,
?int $max = null,
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
try {
$user = $this->actorStore->newActorFromRowFields(
$row->ar_user ?? null,
$row->ar_user_text ?? null,
$row->ar_actor ?? null
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
try {
$user = $this->actorStore->newActorFromRowFields(
$row->rev_user ?? null,
$row->rev_user_text ?? null,
$row->rev_actor ?? null
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76