File EditPage.php
has 3014 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
Method internalAttemptSave
has 399 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function internalAttemptSave( &$result, $markAsBot = false, $markAsMinor = false ) {
$useNPPatrol = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::UseNPPatrol );
$useRCPatrol = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::UseRCPatrol );
if ( !$this->getHookRunner()->onEditPage__attemptSave( $this ) ) {
wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" );
EditPage
has 93 functions (exceeds 20 allowed). Consider refactoring. Open
#[\AllowDynamicProperties]
class EditPage implements IEditObject {
use DeprecationHelper;
use ProtectedHookAccessorTrait;
Function getContentObject
has a Cognitive Complexity of 77 (exceeds 5 allowed). Consider refactoring. Open
protected function getContentObject( $def_content = null ) {
$services = MediaWikiServices::getInstance();
$disableAnonTalk = $services->getMainConfig()->get( MainConfigNames::DisableAnonTalk );
$request = $this->context->getRequest();
- 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 internalAttemptSave
has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring. Open
public function internalAttemptSave( &$result, $markAsBot = false, $markAsMinor = false ) {
$useNPPatrol = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::UseNPPatrol );
$useRCPatrol = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::UseRCPatrol );
if ( !$this->getHookRunner()->onEditPage__attemptSave( $this ) ) {
wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" );
- 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 showEditForm
has 199 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function showEditForm() {
# need to parse the preview early so that we know which templates are used,
# otherwise users with "show preview after edit box" will get a blank list
# we parse this near the beginning so that setHeaders can do the title
# setting work instead of leaving it in getPreviewText
Method getContentObject
has 148 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getContentObject( $def_content = null ) {
$services = MediaWikiServices::getInstance();
$disableAnonTalk = $services->getMainConfig()->get( MainConfigNames::DisableAnonTalk );
$request = $this->context->getRequest();
Function getPreviewText
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
public function getPreviewText() {
$out = $this->context->getOutput();
$config = $this->context->getConfig();
if ( $config->get( MainConfigNames::RawHtml ) && !$this->mTokenOk ) {
- 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 importFormDataPosted
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
private function importFormDataPosted( WebRequest $request ): void {
# These fields need to be checked for encoding.
# Also remove trailing whitespace, but don't remove _initial_
# whitespace from the text boxes. This may be significant formatting.
$this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) );
- 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 showHeader
has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring. Open
private function showHeader(): void {
$out = $this->context->getOutput();
$user = $this->context->getUser();
if ( $this->isConflict ) {
$this->addExplainConflictHeader();
- 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 edit
has 131 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function edit() {
// Allow extensions to modify/prevent this form or submission
if ( !$this->getHookRunner()->onAlternateEdit( $this ) ) {
return;
}
Method importFormDataPosted
has 121 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function importFormDataPosted( WebRequest $request ): void {
# These fields need to be checked for encoding.
# Also remove trailing whitespace, but don't remove _initial_
# whitespace from the text boxes. This may be significant formatting.
$this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) );
Method getPreviewText
has 117 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getPreviewText() {
$out = $this->context->getOutput();
$config = $this->context->getConfig();
if ( $config->get( MainConfigNames::RawHtml ) && !$this->mTokenOk ) {
Function showEditForm
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
public function showEditForm() {
# need to parse the preview early so that we know which templates are used,
# otherwise users with "show preview after edit box" will get a blank list
# we parse this near the beginning so that setHeaders can do the title
# setting work instead of leaving it in getPreviewText
- 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 edit
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
public function edit() {
// Allow extensions to modify/prevent this form or submission
if ( !$this->getHookRunner()->onAlternateEdit( $this ) ) {
return;
}
- 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 handleStatus
has 97 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function handleStatus( Status $status, $resultDetails ): bool {
$statusValue = is_int( $status->value ) ? $status->value : 0;
/**
* @todo FIXME: once the interface for internalAttemptSave() is made
Method showHeader
has 76 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function showHeader(): void {
$out = $this->context->getOutput();
$user = $this->context->getUser();
if ( $this->isConflict ) {
$this->addExplainConflictHeader();
Method importFormData
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function importFormData( &$request ) {
# Section edit can come from either the form or a link
$this->section = $request->getVal( 'wpSection', $request->getVal( 'section', '' ) );
if ( $this->section !== null && $this->section !== '' && !$this->isSectionEditSupported() ) {
Function importFormData
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function importFormData( &$request ) {
# Section edit can come from either the form or a link
$this->section = $request->getVal( 'wpSection', $request->getVal( 'section', '' ) );
if ( $this->section !== null && $this->section !== '' && !$this->isSectionEditSupported() ) {
- 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 setHeaders
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setHeaders() {
$out = $this->context->getOutput();
$out->addModules( 'mediawiki.action.edit' );
$out->addModuleStyles( 'mediawiki.action.edit.styles' );
Function showDiff
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function showDiff() {
$oldtitlemsg = 'currentrev';
# if message does not exist, show diff against the preloaded default
if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI && !$this->mTitle->exists() ) {
$oldtext = $this->mTitle->getDefaultMessageText();
- 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 initialiseForm
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function initialiseForm(): bool {
$this->edittime = $this->page->getTimestamp();
$this->editRevId = $this->page->getLatest();
$dummy = $this->contentHandlerFactory
Method showDiff
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function showDiff() {
$oldtitlemsg = 'currentrev';
# if message does not exist, show diff against the preloaded default
if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI && !$this->mTitle->exists() ) {
$oldtext = $this->mTitle->getDefaultMessageText();
Method getEditButtons
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getEditButtons( &$tabindex ) {
$buttons = [];
$labelAsPublish =
$this->context->getConfig()->get( MainConfigNames::EditSubmitButtonLabelPublish );
Function getPreviewLimitReport
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public static function getPreviewLimitReport( ParserOutput $output = null ) {
if ( !$output || !$output->getLimitReportData() ) {
return '';
}
- 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 displayViewSourcePage
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function displayViewSourcePage( Content $content, string $errorMessage ): void {
$out = $this->context->getOutput();
$this->getHookRunner()->onEditPage__showReadOnlyForm_initial( $this, $out );
$out->setRobotPolicy( 'noindex,nofollow' );
Method getLastDelete
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getLastDelete(): ?stdClass {
$dbr = $this->connectionProvider->getReplicaDatabase();
$commentQuery = $this->commentStore->getJoin( 'log_comment' );
$data = $dbr->selectRow(
array_merge( [ 'logging' ], $commentQuery['tables'], [ 'actor' ] ),
Method getCheckboxesWidget
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getCheckboxesWidget( &$tabindex, $values ) {
$checkboxes = [];
$checkboxesDef = $this->getCheckboxesDefinition( $values );
foreach ( $checkboxesDef as $name => $options ) {
Method getCheckboxesDefinitionForWatchlist
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getCheckboxesDefinitionForWatchlist( $watch, $watchexpiry ): array {
$fieldDefs = [
'wpWatchthis' => [
'id' => 'wpWatchthis',
'label-message' => 'watchthis',
Method getPreviewLimitReport
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getPreviewLimitReport( ParserOutput $output = null ) {
if ( !$output || !$output->getLimitReportData() ) {
return '';
}
Method showIntro
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function showIntro(): void {
$services = MediaWikiServices::getInstance();
// Hardcoded list of notices that are suppressable for historical reasons.
// This feature was originally added for LiquidThreads, to avoid showing non-essential messages
Function setHeaders
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function setHeaders() {
$out = $this->context->getOutput();
$out->addModules( 'mediawiki.action.edit' );
$out->addModuleStyles( 'mediawiki.action.edit.styles' );
- 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 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct( Article $article ) {
$this->mArticle = $article;
$this->page = $article->getPage(); // model object
$this->mTitle = $article->getTitle();
Method showStandardInputs
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function showStandardInputs( &$tabindex = 2 ) {
$out = $this->context->getOutput();
$out->addHTML( "<div class='editOptions'>\n" );
if ( $this->section !== 'new' ) {
Method isUndoClean
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function isUndoClean( Content $content ): bool {
// Check whether the undo was "clean", that is the user has not modified
// the automatically generated content.
$undoRev = $this->revisionStore->getRevisionById( $this->undidRev );
if ( $undoRev === null ) {
Function initialiseForm
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function initialiseForm(): bool {
$this->edittime = $this->page->getTimestamp();
$this->editRevId = $this->page->getLatest();
$dummy = $this->contentHandlerFactory
- 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 addLongPageWarningHeader
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function addLongPageWarningHeader(): void {
if ( $this->contentLength === false ) {
$this->contentLength = strlen( $this->textbox1 );
}
- 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 getTemplates
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function getTemplates() {
if ( $this->preview || $this->section !== '' ) {
$templates = [];
if ( !isset( $this->mParserOutput ) ) {
return $templates;
- 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 handleFailedConstraint
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function handleFailedConstraint( IEditConstraint $failed ): void {
if ( $failed instanceof PageSizeConstraint ) {
// Error will be displayed by showEditForm()
$this->tooBig = true;
} elseif ( $failed instanceof UserBlockConstraint ) {
- 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 handleStatus
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function handleStatus( Status $status, $resultDetails ): bool {
$statusValue = is_int( $status->value ) ? $status->value : 0;
/**
* @todo FIXME: once the interface for internalAttemptSave() is made
- 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 mergeChangesIntoContent
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function mergeChangesIntoContent( Content $editContent ) {
// This is the revision that was current at the time editing was initiated on the client,
// even if the edit was based on an old revision.
$baseRevRecord = $this->getExpectedParentRevision();
$baseContent = $baseRevRecord ?
Method getUndoContent
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getUndoContent( RevisionRecord $undoRev, RevisionRecord $oldRev, &$error ) {
$handler = $this->contentHandlerFactory
->getContentHandler( $undoRev->getSlot(
SlotRecord::MAIN,
RevisionRecord::RAW
Method displayPreviewArea
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function displayPreviewArea( string $previewOutput, bool $isOnTop ): void {
$attribs = [ 'id' => 'wikiPreview' ];
if ( $isOnTop ) {
$attribs['class'] = 'ontop';
}
Function previewOnOpen
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected function previewOnOpen() {
$config = $this->context->getConfig();
$previewOnOpenNamespaces = $config->get( MainConfigNames::PreviewOnOpenNamespaces );
$request = $this->context->getRequest();
if ( $config->get( MainConfigNames::RawHtml ) ) {
- 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 maybeActivateTempUserCreate
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function maybeActivateTempUserCreate( $doAcquire ): Status {
if ( $this->tempUserCreateActive ) {
// Already done
return Status::newGood();
}
- 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 wasDeletedSinceLastEdit
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function wasDeletedSinceLastEdit(): bool {
if ( $this->deletedSinceEdit !== null ) {
return $this->deletedSinceEdit;
}
- 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 isUndoClean
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function isUndoClean( Content $content ): bool {
// Check whether the undo was "clean", that is the user has not modified
// the automatically generated content.
$undoRev = $this->revisionStore->getRevisionById( $this->undidRev );
if ( $undoRev === 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;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return $status;
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return Status::newGood( self::AS_CONFLICT_DETECTED )->setOK( false );
Avoid too many return
statements within this method. Open
return $status;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return Status::newGood( $statusCode );
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return $doEditStatus;
Avoid too many return
statements within this method. Open
return Status::wrap( $failed->getLegacyStatus() );
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return Status::wrap( $failed->getLegacyStatus() );
Avoid too many return
statements within this method. Open
return Status::wrap( $failed->getLegacyStatus() );
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $status;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return Status::wrap( $failed->getLegacyStatus() );
Function getCheckboxesDefinitionForWatchlist
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function getCheckboxesDefinitionForWatchlist( $watch, $watchexpiry ): array {
$fieldDefs = [
'wpWatchthis' => [
'id' => 'wpWatchthis',
'label-message' => 'watchthis',
- 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 displayViewSourcePage
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function displayViewSourcePage( Content $content, string $errorMessage ): void {
$out = $this->context->getOutput();
$this->getHookRunner()->onEditPage__showReadOnlyForm_initial( $this, $out );
$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 displayPreviewArea
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function displayPreviewArea( string $previewOutput, bool $isOnTop ): void {
$attribs = [ 'id' => 'wikiPreview' ];
if ( $isOnTop ) {
$attribs['class'] = 'ontop';
}
- 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 getUserForPreview
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function getUserForPreview() {
if ( $this->savedTempUser ) {
return $this->savedTempUser;
} elseif ( $this->unsavedTempUser ) {
return $this->unsavedTempUser;
- 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
$buttons['preview'] = new OOUI\ButtonInputWidget( [
'name' => 'wpPreview',
'tabIndex' => ++$tabindex,
'id' => 'wpPreviewWidget',
'inputId' => 'wpPreview',
- 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 110.
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
$buttons['diff'] = new OOUI\ButtonInputWidget( [
'name' => 'wpDiff',
'tabIndex' => ++$tabindex,
'id' => 'wpDiffWidget',
'inputId' => 'wpDiff',
- 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 110.
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