File DefaultPreferencesFactory.php
has 1521 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 profilePreferences
has 421 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function profilePreferences(
User $user, IContextSource $context, &$defaultPreferences
) {
// retrieving user name for GENDER and misc.
$userName = $user->getName();
Function profilePreferences
has a Cognitive Complexity of 82 (exceeds 5 allowed). Consider refactoring. Open
protected function profilePreferences(
User $user, IContextSource $context, &$defaultPreferences
) {
// retrieving user name for GENDER and misc.
$userName = $user->getName();
- 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 watchlistPreferences
has 143 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function watchlistPreferences(
User $user, IContextSource $context, &$defaultPreferences
) {
$watchlistdaysMax = ceil( $this->options->get( MainConfigNames::RCMaxAge ) / ( 3600 * 24 ) );
Method rcPreferences
has 87 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function rcPreferences( User $user, MessageLocalizer $l10n, &$defaultPreferences ) {
$rcMaxAge = $this->options->get( MainConfigNames::RCMaxAge );
$rcMax = ceil( $rcMaxAge / ( 3600 * 24 ) );
$defaultPreferences['rcdays'] = [
'type' => 'float',
DefaultPreferencesFactory
has 28 functions (exceeds 20 allowed). Consider refactoring. Open
class DefaultPreferencesFactory implements PreferencesFactory {
use LoggerAwareTrait;
/** @var ServiceOptions */
protected $options;
Function getOptionFromUser
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
protected function getOptionFromUser( $name, $info, array $userOptions ) {
$val = $userOptions[$name] ?? null;
// Handling for multiselect preferences
if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
- 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 editingPreferences
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function editingPreferences( User $user, MessageLocalizer $l10n, &$defaultPreferences ) {
$defaultPreferences['editsectiononrightclick'] = [
'type' => 'toggle',
'section' => 'editing/advancedediting',
'label-message' => 'tog-editsectiononrightclick',
Function skinPreferences
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
protected function skinPreferences( User $user, IContextSource $context, &$defaultPreferences ) {
// Skin selector, if there is at least one valid skin
$validSkinNames = $this->getValidSkinNames( $user, $context );
if ( $validSkinNames ) {
$defaultPreferences['skin'] = [
- 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 searchPreferences
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function searchPreferences( $context, &$defaultPreferences ) {
$defaultPreferences['search-special-page'] = [
'type' => 'api',
];
Method skinPreferences
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function skinPreferences( User $user, IContextSource $context, &$defaultPreferences ) {
// Skin selector, if there is at least one valid skin
$validSkinNames = $this->getValidSkinNames( $user, $context );
if ( $validSkinNames ) {
$defaultPreferences['skin'] = [
Method datetimePreferences
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function datetimePreferences(
User $user, IContextSource $context, &$defaultPreferences
) {
$dateOptions = $this->getDateOptions( $context );
if ( $dateOptions ) {
Function simplifyFormDescriptor
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public static function simplifyFormDescriptor( array $descriptor ) {
foreach ( $descriptor as $name => &$params ) {
// Info fields are useless and can use complicated closure to provide
// text, skip all of them.
if ( ( isset( $params['type'] ) && $params['type'] === 'info' ) ||
- 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 15 arguments (exceeds 4 allowed). Consider refactoring. Open
ServiceOptions $options,
Language $contLang,
AuthManager $authManager,
LinkRenderer $linkRenderer,
NamespaceInfo $nsInfo,
Function generateSkinOptions
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
protected function generateSkinOptions( User $user, IContextSource $context, array $validSkinNames ) {
$ret = [];
$mptitle = Title::newMainPage();
$previewtext = $context->msg( 'skin-preview' )->escaped();
- 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 renderingPreferences
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function renderingPreferences(
User $user,
MessageLocalizer $l10n,
&$defaultPreferences
) {
Method generateSkinOptions
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function generateSkinOptions( User $user, IContextSource $context, array $validSkinNames ) {
$ret = [];
$mptitle = Title::newMainPage();
$previewtext = $context->msg( 'skin-preview' )->escaped();
Method saveFormData
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function saveFormData( $formData, PreferencesFormOOUI $form, array $formDescriptor ) {
$user = $form->getModifiedUser();
$hiddenPrefs = $this->options->get( MainConfigNames::HiddenPrefs );
$result = true;
Function loadPreferenceValues
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private function loadPreferenceValues( User $user, IContextSource $context, &$defaultPreferences ) {
// Remove preferences that wikis don't want to use
foreach ( $this->options->get( MainConfigNames::HiddenPrefs ) as $pref ) {
unset( $defaultPreferences[$pref] );
}
- 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 validateSignature
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
protected function validateSignature( $signature, $alldata, HTMLForm $form ) {
$sigValidation = $this->options->get( MainConfigNames::SignatureValidation );
$maxSigChars = $this->options->get( MainConfigNames::MaxSigChars );
if ( is_string( $signature ) && mb_strlen( $signature ) > $maxSigChars ) {
return $form->msg( 'badsiglength' )->numParams( $maxSigChars )->escaped();
- 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 saveFormData
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
protected function saveFormData( $formData, PreferencesFormOOUI $form, array $formDescriptor ) {
$user = $form->getModifiedUser();
$hiddenPrefs = $this->options->get( MainConfigNames::HiddenPrefs );
$result = 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
Method loadPreferenceValues
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function loadPreferenceValues( User $user, IContextSource $context, &$defaultPreferences ) {
// Remove preferences that wikis don't want to use
foreach ( $this->options->get( MainConfigNames::HiddenPrefs ) as $pref ) {
unset( $defaultPreferences[$pref] );
}
Function getDateOptions
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
protected function getDateOptions( IContextSource $context ) {
$lang = $context->getLanguage();
$dateopts = $lang->getDatePreferences();
$ret = [];
- 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 validateSignature
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function validateSignature( $signature, $alldata, HTMLForm $form ) {
$sigValidation = $this->options->get( MainConfigNames::SignatureValidation );
$maxSigChars = $this->options->get( MainConfigNames::MaxSigChars );
if ( is_string( $signature ) && mb_strlen( $signature ) > $maxSigChars ) {
return $form->msg( 'badsiglength' )->numParams( $maxSigChars )->escaped();
Method getForm
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getForm(
User $user,
IContextSource $context,
$formClass = PreferencesFormOOUI::class,
array $remove = []
Function applyFilters
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function applyFilters( array &$preferences, array $formDescriptor, $verb ) {
foreach ( $formDescriptor as $preference => $desc ) {
if ( !isset( $desc['filter'] ) || !isset( $preferences[$preference] ) ) {
continue;
}
- 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 sortSkinNames
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static function sortSkinNames( $a, $b, $currentSkin, $preferredSkins ) {
// Display the current skin first in the list
if ( strcasecmp( $a, $currentSkin ) === 0 ) {
return -1;
}
- 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 watchlistPreferences
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function watchlistPreferences(
User $user, IContextSource $context, &$defaultPreferences
) {
$watchlistdaysMax = ceil( $this->options->get( MainConfigNames::RCMaxAge ) / ( 3600 * 24 ) );
- 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 getOptionFromUser
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getOptionFromUser( $name, $info, array $userOptions ) {
$val = $userOptions[$name] ?? null;
// Handling for multiselect preferences
if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
Avoid too many return
statements within this method. Open
return strcasecmp( $aPreferred, $bPreferred );
Avoid too many return
statements within this method. Open
return strcasecmp( $a, $b );
Avoid too many return
statements within this method. Open
return $form->msg( 'badsig' )->escaped();
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return $errors;
Function getPreferenceForField
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function getPreferenceForField( $name, HTMLFormField $field, array $userOptions ) {
$val = $userOptions[$name] ?? null;
if ( $field instanceof HTMLNestedFilterable ) {
$val = [];
- 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 getValidSkinNames
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function getValidSkinNames( User $user, IContextSource $context ) {
// Only show skins that aren't disabled
$validSkinNames = $this->skinFactory->getAllowedSkins();
$allInstalledSkins = $this->skinFactory->getInstalledSkins();
- 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"