Showing 1,238 of 1,238 total issues
Identical blocks of code found in 4 locations. Consider refactoring. Open
api.postWithToken( 'csrf', params )
.done( successFunction )
.fail( function ( code, data ) {
// eslint-disable-next-line no-alert
alert( data.error && data.error.info );
- 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 60.
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
Function getDefinitions
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function getDefinitions() {
$groups = MessageGroups::getAllGroups();
$keys = [];
/** @var $g MessageGroup */
- 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 6 locations. Consider refactoring. Open
saturate: function (ratio) {
var hsl = this.values.hsl;
hsl[1] += hsl[1] * ratio;
this.setValues('hsl', hsl);
return this;
- 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 60.
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
Function exports
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function ( grunt ) {
const conf = grunt.file.readJSON( 'extension.json' );
grunt.loadNpmTasks( 'grunt-eslint' );
grunt.loadNpmTasks( 'grunt-banana-checker' );
Function showShortcuts
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
showShortcuts: function () {
// Any better way?
var rtl = $( document.body ).is( '.rtl' );
var editorOffset = this.$editor.offset();
Function saveDocumentation
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
saveDocumentation: function () {
var translateEditor = this,
api = new mw.Api(),
newDocumentation = translateEditor.$editor.find( '.tux-textarea-documentation' ).val();
Function calculatePointY
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
calculatePointY: function(value, index, datasetIndex) {
var me = this;
var chart = me.chart;
var yScale = me._yScale;
var sumPos = 0;
Function hsl
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
convert.rgb.hsl = function (rgb) {
var r = rgb[0] / 255;
var g = rgb[1] / 255;
var b = rgb[2] / 255;
var min = Math.min(r, g, b);
Function proofread
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
proofread: function () {
var message = this.message,
$message = this.$message,
api = new mw.Api();
Function listen
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
listen: function () {
var statsbar = this;
statsbar.$statsBar.on( 'change', function ( event, to, from ) {
// This updates the value in mw.translate.languagestats as a reference to
// the object is returned here.
Function rgb
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
convert.hcg.rgb = function (hcg) {
var h = hcg[0] / 360;
var c = hcg[1] / 100;
var g = hcg[2] / 100;
Function handleEvent
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
handleEvent: function(e) {
var me = this;
var opts = me.options;
var type = e.type === 'mouseup' ? 'click' : e.type;
var hoveredItem;
Method getArrayDiff
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getArrayDiff( array $old, array $new ): array {
$values = [];
$record = static function ( $groups ) use ( &$values ) {
foreach ( $groups as $group ) {
$values[$group] = true;
Method execute
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function execute() {
$this->contentLanguage = MediaWikiServices::getInstance()->getContentLanguage();
$threads = (int)$this->getOption( 'threads', 1 );
$outputDir = $this->getOption( 'output-directory' );
Method createQueryBuilder
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function createQueryBuilder( IReadableDatabase $database, string $caller ): SelectQueryBuilder {
global $wgTranslateMessageNamespaces;
$fields = [ 'log_timestamp' ];
Method normalize
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function normalize( array $validCounts ): void {
$this->formOptions->validateIntBounds( 'days', 1, 10000 );
$this->formOptions->validateIntBounds( 'width', 200, 1000 );
$this->formOptions->validateIntBounds( 'height', 200, 1000 );
Method onArticleViewHeader
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function onArticleViewHeader( $article, &$outputDone, &$pcache ) {
if ( !$this->enableIntegration ) {
return;
}
Method levenshtein
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function levenshtein( string $str1, string $str2, int $length1, int $length2 ): int {
if ( $length1 === 0 ) {
return $length2;
}
Method getLatestRevisionsForTags
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getLatestRevisionsForTags( PageIdentity $identity, string ...$tags ): ?array {
if ( !$identity->exists() ) {
return null;
}
Method addValidator
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addValidator( array $validatorConfig ): void {
$validatorId = $validatorConfig['id'] ?? null;
$className = $validatorConfig['class'] ?? null;
if ( $validatorId !== null ) {