File DifferenceEngine.php
has 1431 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* User interface for the difference engine.
*
* This program is free software; you can redistribute it and/or modify
Method showDiffPage
has 260 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function showDiffPage( $diffOnly = false ) {
# Allow frames except in certain special cases
$out = $this->getOutput();
$out->setPreventClickjacking( false );
$out->setRobotPolicy( 'noindex,nofollow' );
DifferenceEngine
has 68 functions (exceeds 20 allowed). Consider refactoring. Open
class DifferenceEngine extends ContextSource {
use DeprecationHelper;
/**
Function showDiffPage
has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring. Open
public function showDiffPage( $diffOnly = false ) {
# Allow frames except in certain special cases
$out = $this->getOutput();
$out->setPreventClickjacking( false );
$out->setRobotPolicy( 'noindex,nofollow' );
- 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 getDiffBody
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
public function getDiffBody() {
$this->mCacheHit = true;
// Check if the diff should be hidden from this user
if ( !$this->isContentOverridden ) {
if ( !$this->loadRevisionData() ) {
- 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 loadRevisionData
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
public function loadRevisionData() {
if ( $this->mRevisionsLoaded ) {
return $this->isContentOverridden ||
( $this->mOldRevisionRecord !== null && $this->mNewRevisionRecord !== 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 getDiffBody
has 75 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getDiffBody() {
$this->mCacheHit = true;
// Check if the diff should be hidden from this user
if ( !$this->isContentOverridden ) {
if ( !$this->loadRevisionData() ) {
Function renderNewRevision
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public function renderNewRevision() {
if ( $this->isContentOverridden ) {
// The code below only works with a RevisionRecord object. We could construct a
// fake RevisionRecord (here or in setContent), but since this does not seem
// needed at the moment, we'll just fail for now.
- 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 loadRevisionData
has 70 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function loadRevisionData() {
if ( $this->mRevisionsLoaded ) {
return $this->isContentOverridden ||
( $this->mOldRevisionRecord !== null && $this->mNewRevisionRecord !== null );
}
Method renderNewRevision
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function renderNewRevision() {
if ( $this->isContentOverridden ) {
// The code below only works with a RevisionRecord object. We could construct a
// fake RevisionRecord (here or in setContent), but since this does not seem
// needed at the moment, we'll just fail for now.
Method getMultiNotice
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getMultiNotice() {
// The notice only make sense if we are diffing two saved revisions of the same page.
if (
!$this->mOldRevisionRecord || !$this->mNewRevisionRecord
|| !$this->mOldPage || !$this->mNewPage
Function getMultiNotice
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function getMultiNotice() {
// The notice only make sense if we are diffing two saved revisions of the same page.
if (
!$this->mOldRevisionRecord || !$this->mNewRevisionRecord
|| !$this->mOldPage || !$this->mNewPage
- 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 getRevisionHeader
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getRevisionHeader( RevisionRecord $rev, $complete = '' ) {
$lang = $this->getLanguage();
$user = $this->getUser();
$revtimestamp = $rev->getTimestamp();
$timestamp = $lang->userTimeAndDate( $revtimestamp, $user );
Method addHeader
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
// shared.css sets diff in interface language/dir, but the actual content
// is often in a different language, mostly the page content language/dir
$header = Html::openElement( 'table', [
'class' => [
Consider simplifying this complex logical expression. Open
if (
!$this->mOldRevisionRecord || !$this->mNewRevisionRecord
|| !$this->mOldPage || !$this->mNewPage
|| !$this->mOldPage->equals( $this->mNewPage )
|| $this->mOldRevisionRecord->getId() === null
Function mapDiffPrevNext
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function mapDiffPrevNext( $old, $new ) {
if ( $new === 'prev' ) {
// Show diff between revision $old and the previous one. Get previous one from DB.
$newid = intval( $old );
$oldid = 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 addHeader
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
// shared.css sets diff in interface language/dir, but the actual content
// is often in a different language, mostly the page content language/dir
$header = Html::openElement( 'table', [
'class' => [
- 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 getSlotDiffRenderers
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
protected function getSlotDiffRenderers() {
if ( $this->isSlotDiffRenderer ) {
throw new LogicException( __METHOD__ . ' called in slot diff renderer mode' );
}
- 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 getMarkPatrolledLinkInfo
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getMarkPatrolledLinkInfo() {
$user = $this->getUser();
$config = $this->getConfig();
// Prepare a change patrol link, if applicable
Method getSlotContents
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getSlotContents() {
if ( $this->isContentOverridden ) {
return [
SlotRecord::MAIN => [ 'old' => $this->mOldContent, 'new' => $this->mNewContent ]
];
Method loadText
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function loadText() {
if ( $this->mTextLoaded == 2 ) {
return $this->loadRevisionData() &&
( $this->mOldRevisionRecord === false || $this->mOldContent )
&& $this->mNewContent;
Function getMarkPatrolledLinkInfo
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function getMarkPatrolledLinkInfo() {
$user = $this->getUser();
$config = $this->getConfig();
// Prepare a change patrol link, if applicable
- 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 getSlotDiffRenderers
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getSlotDiffRenderers() {
if ( $this->isSlotDiffRenderer ) {
throw new LogicException( __METHOD__ . ' called in slot diff renderer mode' );
}
Function loadText
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function loadText() {
if ( $this->mTextLoaded == 2 ) {
return $this->loadRevisionData() &&
( $this->mOldRevisionRecord === false || $this->mOldContent )
&& $this->mNewContent;
- 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 __construct
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public function __construct( $context = null, $old = 0, $new = 0, $rcid = 0,
$refreshCache = false, $unhide = false
Method addHeader
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return $difftext;
Avoid too many return
statements within this method. Open
return $difftext;
Function getRevisionHeader
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getRevisionHeader( RevisionRecord $rev, $complete = '' ) {
$lang = $this->getLanguage();
$user = $this->getUser();
$revtimestamp = $rev->getTimestamp();
$timestamp = $lang->userTimeAndDate( $revtimestamp, $user );
- 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
if ( $hasPrevious ) {
$prevlinkQuery = [ 'diff' => 'prev', 'oldid' => $this->mOldid ] + $query;
$prevlink = $this->linkRenderer->makeKnownLink(
$this->mOldPage,
$this->msg( 'previousdiff' )->text(),
- 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 107.
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
if ( $samePage && $this->mNewPage && !$this->mNewRevisionRecord->isCurrent() ) {
$nextlinkQuery = [ 'diff' => 'next', 'oldid' => $this->mNewid ] + $query;
$nextlink = $this->linkRenderer->makeKnownLink(
$this->mNewPage,
$this->msg( 'nextdiff' )->text(),
- 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 107.
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