File Hooks.php
has 1201 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace MediaWiki\Extension\Translate\PageTranslation;
use Article;
Hooks
has 41 functions (exceeds 20 allowed). Consider refactoring. Open
class Hooks {
private const PAGEPROP_HAS_LANGUAGES_TAG = 'translate-has-languages-tag';
/** @var bool Uuugly hacks */
public static $allowTargetEdit = false;
/** State flag used by DeleteTranslatableBundleJob for performance optimizations. */
Method languages
has 107 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function languages( $data, $params, $parser ) {
global $wgPageTranslationLanguageList;
if ( $wgPageTranslationLanguageList === 'sidebar-only' ) {
return '';
Function onGetUserPermissionsErrorsExpensive
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
public static function onGetUserPermissionsErrorsExpensive(
Title $title,
User $user,
$action,
&$result
- 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 replaceSubtitle
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public static function replaceSubtitle( &$subpages, ?Skin $skin, OutputPage $out ) {
$linker = MediaWikiServices::getInstance()->getLinkRenderer();
$isTranslationPage = TranslatablePage::isTranslationPage( $out->getTitle() );
if ( !$isTranslationPage
- 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 onGetUserPermissionsErrorsExpensive
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function onGetUserPermissionsErrorsExpensive(
Title $title,
User $user,
$action,
&$result
Method addLanguageLinks
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function addLanguageLinks( Title $title, array &$languageLinks ) {
global $wgPageTranslationLanguageList;
if ( $wgPageTranslationLanguageList === 'tag-only' ) {
return;
Method renderTagPage
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function renderTagPage( $wikitextParser, &$text, $state ): void {
if ( $text === null ) {
// SMW is unhelpfully sending null text if the source contains section tags. Do not explode.
return;
}
Method translationPageHeader
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function translationPageHeader( IContextSource $context, TranslatablePage $page ) {
global $wgTranslateKeepOutdatedTranslations;
$title = $context->getTitle();
if ( !$title->exists() ) {
Method replaceSubtitle
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function replaceSubtitle( &$subpages, ?Skin $skin, OutputPage $out ) {
$linker = MediaWikiServices::getInstance()->getLinkRenderer();
$isTranslationPage = TranslatablePage::isTranslationPage( $out->getTitle() );
if ( !$isTranslationPage
Function onMovePageTranslationUnits
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public static function onMovePageTranslationUnits(
LinkTarget $oldLinkTarget,
LinkTarget $newLinkTarget,
UserIdentity $userIdentity,
int $oldid,
- 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 fetchTranslatableTemplateAndTitle
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public static function fetchTranslatableTemplateAndTitle(
?LinkTarget $contextLink,
?LinkTarget $templateLink,
bool &$skip,
?RevisionRecord &$revRecord
- 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 onDeleteTranslationUnit
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function onDeleteTranslationUnit(
WikiPage $unit,
User $user,
$reason,
$id,
Method fetchTranslatableTemplateAndTitle
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function fetchTranslatableTemplateAndTitle(
?LinkTarget $contextLink,
?LinkTarget $templateLink,
bool &$skip,
?RevisionRecord &$revRecord
Method sourcePageHeader
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function sourcePageHeader( IContextSource $context ) {
$linker = MediaWikiServices::getInstance()->getLinkRenderer();
$language = $context->getLanguage();
$title = $context->getTitle();
Method preventDirectEditing
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function preventDirectEditing( Title $title, User $user, $action, &$result ) {
if ( self::$allowTargetEdit ) {
return true;
}
Function languages
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static function languages( $data, $params, $parser ) {
global $wgPageTranslationLanguageList;
if ( $wgPageTranslationLanguageList === 'sidebar-only' ) {
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 translateTab
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function translateTab( Skin $skin, array &$tabs ) {
$title = $skin->getTitle();
$handle = new MessageHandle( $title );
$code = $handle->getCode();
$page = TranslatablePage::isTranslationPage( $title );
Function sourcePageHeader
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private static function sourcePageHeader( IContextSource $context ) {
$linker = MediaWikiServices::getInstance()->getLinkRenderer();
$language = $context->getLanguage();
$title = $context->getTitle();
- 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 addLanguageLinks
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function addLanguageLinks( Title $title, array &$languageLinks ) {
global $wgPageTranslationLanguageList;
if ( $wgPageTranslationLanguageList === 'tag-only' ) {
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 translatablePageHeader
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function translatablePageHeader( $article, &$outputDone, &$pcache ) {
if ( $article->getOldID() ) {
return;
}
Method onMovePageTranslationUnits
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function onMovePageTranslationUnits(
LinkTarget $oldLinkTarget,
LinkTarget $newLinkTarget,
UserIdentity $userIdentity,
int $oldid,
Function translateTab
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function translateTab( Skin $skin, array &$tabs ) {
$title = $skin->getTitle();
$handle = new MessageHandle( $title );
$code = $handle->getCode();
$page = TranslatablePage::isTranslationPage( $title );
- 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 updateTranslationPage
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
TranslatablePage $page,
string $code,
User $user,
int $flags,
string $summary,
Method onMovePageTranslationUnits
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
LinkTarget $oldLinkTarget,
LinkTarget $newLinkTarget,
UserIdentity $userIdentity,
int $oldid,
int $newid,
Method onSectionSave
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
WikiPage $wikiPage,
User $user,
TextContent $content,
$summary,
$minor,
Method addTranstagAfterSave
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
WikiPage $wikiPage,
UserIdentity $userIdentity,
string $summary,
int $flags,
RevisionRecord $revisionRecord,
Method onDeleteTranslationUnit
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
WikiPage $unit,
User $user,
$reason,
$id,
$content,
Function getTranslationRestrictions
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private static function getTranslationRestrictions( MessageHandle $handle, $groupId ) {
global $wgTranslateDocumentationLanguageCode;
// Allow adding message documentation even when translation is restricted
if ( $handle->getCode() === $wgTranslateDocumentationLanguageCode ) {
- 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 tpSyntaxCheck
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
RenderedRevision $renderedRevision,
UserIdentity $user,
CommentStoreComment $summary,
$flags,
Status $hookStatus
Method onParserGetVariableValueSwitch
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Parser $parser,
array &$variableCache,
string $magicWordId,
?string &$ret,
PPFrame $frame
Function preventDirectEditing
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function preventDirectEditing( Title $title, User $user, $action, &$result ) {
if ( self::$allowTargetEdit ) {
return true;
}
- 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 renderTagPage
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function renderTagPage( $wikitextParser, &$text, $state ): void {
if ( $text === null ) {
// SMW is unhelpfully sending null text if the source contains section tags. Do not explode.
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
Function translationPageHeader
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static function translationPageHeader( IContextSource $context, TranslatablePage $page ) {
global $wgTranslateKeepOutdatedTranslations;
$title = $context->getTitle();
if ( !$title->exists() ) {
- 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 [ 'tpt-translation-restricted', $reason ];
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 [ 'tpt-translation-restricted-no-reason' ];
Avoid too many return
statements within this method. Open
return $error === [];
Avoid too many return
statements within this method. Open
return [];
Avoid too many return
statements within this method. Open
return;
Function getTranslatablePageStatus
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function getTranslatablePageStatus( ?PageReference $pageReference ): ?array {
if ( $pageReference === null ) {
return null;
}
$title = Title::newFromPageReference( $pageReference );
- 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 onDeleteTranslationUnit
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function onDeleteTranslationUnit(
WikiPage $unit,
User $user,
$reason,
$id,
- 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 onTitleGetEditNotices
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function onTitleGetEditNotices( Title $title, int $oldid, array &$notices ) {
if ( TranslatablePage::isSourcePage( $title ) ) {
$msg = wfMessage( 'translate-edit-tag-warning' )->inContentLanguage();
if ( !$msg->isDisabled() ) {
$notices['translate-tag'] = $msg->parseAsBlock();
- 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 translatablePageHeader
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function translatablePageHeader( $article, &$outputDone, &$pcache ) {
if ( $article->getOldID() ) {
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
Function onBeforePageDisplay
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) {
global $wgTranslatePageTranslationULS;
$title = $out->getTitle();
$isSource = TranslatablePage::isSourcePage( $title );
- 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"