File SpecialUndelete.php
has 1294 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Implements Special:Undelete
*
* This program is free software; you can redistribute it and/or modify
Method showHistory
has 261 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function showHistory() {
$this->checkReadOnly();
$out = $this->getOutput();
if ( $this->mAllowed ) {
Method showRevision
has 176 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function showRevision( $timestamp ) {
if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
return;
}
$out = $this->getOutput();
Function showHistory
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
protected function showHistory() {
$this->checkReadOnly();
$out = $this->getOutput();
if ( $this->mAllowed ) {
- 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
SpecialUndelete
has 29 functions (exceeds 20 allowed). Consider refactoring. Open
class SpecialUndelete extends SpecialPage {
/**
* Limit of revisions (Page history) to display.
* (If there are more items to display - "Load more" button will appear).
Function execute
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
public function execute( $par ) {
$this->useTransactionalTimeLimit();
$user = $this->getUser();
- 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 showRevision
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
private function showRevision( $timestamp ) {
if ( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
return;
}
$out = $this->getOutput();
- 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 formatRevisionRow
has 76 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
$revRecord = $this->revisionStore->newRevisionFromArchiveRow(
$row,
IDBAccessObject::READ_NORMAL,
$this->mTargetObj
Function loadRequest
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
private function loadRequest( $par ) {
$request = $this->getRequest();
$user = $this->getUser();
$this->mAction = $request->getRawVal( 'action' );
- 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 loadRequest
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function loadRequest( $par ) {
$request = $this->getRequest();
$user = $this->getUser();
$this->mAction = $request->getRawVal( 'action' );
Function formatRevisionRow
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
protected function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
$revRecord = $this->revisionStore->newRevisionFromArchiveRow(
$row,
IDBAccessObject::READ_NORMAL,
$this->mTargetObj
- 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 diffHeader
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function diffHeader( RevisionRecord $revRecord, $prefix ) {
if ( $revRecord instanceof RevisionArchiveRecord ) {
// Revision in the archive table, only viewable via this special page
$targetPage = $this->getPageTitle();
$targetQuery = [
Method showSearchForm
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function showSearchForm() {
$out = $this->getOutput();
$out->setPageTitleMsg( $this->msg( 'undelete-search-title' ) );
$fuzzySearch = $this->getRequest()->getVal( 'fuzzy', '1' );
Method execute
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function execute( $par ) {
$this->useTransactionalTimeLimit();
$user = $this->getUser();
Method undelete
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function undelete() {
if ( $this->getConfig()->get( MainConfigNames::UploadMaintenance )
&& $this->mTargetObj->getNamespace() === NS_FILE
) {
throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
Method __construct
has 15 arguments (exceeds 4 allowed). Consider refactoring. Open
PermissionManager $permissionManager,
RevisionStore $revisionStore,
RevisionRenderer $revisionRenderer,
IContentHandlerFactory $contentHandlerFactory,
NameTableStore $changeTagDefStore,
Method showList
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function showList( $result ) {
$out = $this->getOutput();
if ( $result->numRows() == 0 ) {
$out->addWikiMsg( 'undelete-no-results' );
Method formatFileRow
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function formatFileRow( $row ) {
$file = ArchivedFile::newFromRow( $row );
$ts = wfTimestamp( TS_MW, $row->fa_timestamp );
$user = $this->getUser();
Function formatFileRow
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private function formatFileRow( $row ) {
$file = ArchivedFile::newFromRow( $row );
$ts = wfTimestamp( TS_MW, $row->fa_timestamp );
$user = $this->getUser();
- 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 getFileLink
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getFileLink( $file, $titleObj, $ts, $key ) {
$user = $this->getUser();
$time = $this->getLanguage()->userTimeAndDate( $ts, $user );
if ( !$file->userCan( File::DELETED_FILE, $user ) ) {
Function diffHeader
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function diffHeader( RevisionRecord $revRecord, $prefix ) {
if ( $revRecord instanceof RevisionArchiveRecord ) {
// Revision in the archive table, only viewable via this special page
$targetPage = $this->getPageTitle();
$targetQuery = [
- 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 undelete
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function undelete() {
if ( $this->getConfig()->get( MainConfigNames::UploadMaintenance )
&& $this->mTargetObj->getNamespace() === NS_FILE
) {
throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
- 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;
Function redirectToRevDel
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function redirectToRevDel() {
$revisions = [];
foreach ( $this->getRequest()->getValues() as $key => $val ) {
$matches = [];
- 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 4 locations. Consider refactoring. Open
public function __construct(
PermissionManager $permissionManager,
RevisionStore $revisionStore,
RevisionRenderer $revisionRenderer,
IContentHandlerFactory $contentHandlerFactory,
- 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 106.
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