fisharebest/webtrees

View on GitHub
resources/js/webtrees.js

Summary

Maintainability
F
6 days
Test Coverage

File webtrees.js has 737 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * webtrees: online genealogy
 * Copyright (C) 2023 webtrees development team
 * 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
Severity: Major
Found in resources/js/webtrees.js - About 1 day to fix

    Function reformatDate has 88 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      webtrees.reformatDate = function (datefield, dmy) {
        const months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
        const hijri_months = ['MUHAR', 'SAFAR', 'RABIA', 'RABIT', 'JUMAA', 'JUMAT', 'RAJAB', 'SHAAB', 'RAMAD', 'SHAWW', 'DHUAQ', 'DHUAH'];
        const hebrew_months = ['TSH', 'CSH', 'KSL', 'TVT', 'SHV', 'ADR', 'ADS', 'NSN', 'IYR', 'SVN', 'TMZ', 'AAV', 'ELL'];
        const french_months = ['VEND', 'BRUM', 'FRIM', 'NIVO', 'PLUV', 'VENT', 'GERM', 'FLOR', 'PRAI', 'MESS', 'THER', 'FRUC', 'COMP'];
    Severity: Major
    Found in resources/js/webtrees.js - About 3 hrs to fix

      Function calGenerateSelectorContent has 68 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function calGenerateSelectorContent (dateFieldId, dateDivId, date) {
          let i, j;
          let content = '<table border="1"><tr>';
          content += '<td><select class="form-select" id="' + dateFieldId + '_daySelect" onchange="return webtrees.calUpdateCalendar(\'' + dateFieldId + '\', \'' + dateDivId + '\');">';
          for (i = 1; i < 32; i++) {
      Severity: Major
      Found in resources/js/webtrees.js - About 2 hrs to fix

        Function calLocalize has 20 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          webtrees.calLocalize = function (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec, sun, mon, tue, wed, thu, fri, sat, day) {
        Severity: Major
        Found in resources/js/webtrees.js - About 2 hrs to fix

          Function buildLeafletJsMap has 61 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            webtrees.buildLeafletJsMap = function (id, config, resetCallback) {
              const zoomControl = new L.control.zoom({
                zoomInTitle: config.i18n.zoomIn,
                zoomoutTitle: config.i18n.zoomOut,
              });
          Severity: Major
          Found in resources/js/webtrees.js - About 2 hrs to fix

            Function initializeTomSelect has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              webtrees.initializeTomSelect = function (element) {
                if (element.tomselect) {
                  return element.tomselect;
                }
            
            
            Severity: Minor
            Found in resources/js/webtrees.js - About 1 hr to fix

              Function calendarWidget has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                webtrees.calendarWidget = function (dateDivId, dateFieldId) {
                  let dateDiv = document.getElementById(dateDivId);
                  let dateField = document.getElementById(dateFieldId);
              
                  if (dateDiv.style.visibility === 'visible') {
              Severity: Minor
              Found in resources/js/webtrees.js - About 1 hr to fix

                Function autocomplete has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  webtrees.autocomplete = function (selector) {
                    // Use typeahead/bloodhound for autocomplete
                    $(selector).each(function () {
                      const that = this;
                      $(this).typeahead(null, {
                Severity: Minor
                Found in resources/js/webtrees.js - About 1 hr to fix

                  Function reformatLatLong has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    function reformatLatLong (field, pos, neg) {
                      // valid LATI or LONG according to Gedcom standard
                      // pos (+) : N or E
                      // neg (-) : S or W
                      let txt = field.value.toUpperCase();
                  Severity: Minor
                  Found in resources/js/webtrees.js - About 1 hr to fix

                    Function buildNameFromParts has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                      webtrees.buildNameFromParts = function (npfx, givn, spfx, surn, nsfx, sex) {
                    Severity: Minor
                    Found in resources/js/webtrees.js - About 45 mins to fix

                      Function calDateClicked has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                        webtrees.calDateClicked = function (dateFieldId, dateDivId, year, month, day) {
                      Severity: Minor
                      Found in resources/js/webtrees.js - About 35 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            return new TomSelect(element, { });
                        Severity: Major
                        Found in resources/js/webtrees.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                              return false;
                          Severity: Major
                          Found in resources/js/webtrees.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                return false;
                            Severity: Major
                            Found in resources/js/webtrees.js - About 30 mins to fix

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                    if ((dmy === 'MDY' || f2 > 13 && f3 > 31) && f1 <= 12 && f2 <= 31) {
                                      return f2 + ' ' + months[f1 - 1] + ' ' + (f3 >= 100 ? f3 : (f3 <= yy ? f3 + cc : f3 + cc - 100));
                                    }
                              Severity: Major
                              Found in resources/js/webtrees.js and 1 other location - About 3 hrs to fix
                              resources/js/webtrees.js on lines 228..230

                              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 102.

                              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

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                    if ((dmy === 'DMY' || f1 > 13 && f3 > 31) && f1 <= 31 && f2 <= 12) {
                                      return f1 + ' ' + months[f2 - 1] + ' ' + (f3 >= 100 ? f3 : (f3 <= yy ? f3 + cc : f3 + cc - 100));
                                    }
                              Severity: Major
                              Found in resources/js/webtrees.js and 1 other location - About 3 hrs to fix
                              resources/js/webtrees.js on lines 231..233

                              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 102.

                              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

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                    if (RegExp.$1 <= '31' && RegExp.$2 <= '12' && RegExp.$3 > '12') {
                                      return RegExp.$1 + ' ' + months[RegExp.$2 - 1] + ' ' + RegExp.$3 + RegExp.$4;
                                    }
                              Severity: Major
                              Found in resources/js/webtrees.js and 1 other location - About 2 hrs to fix
                              resources/js/webtrees.js on lines 211..213

                              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 86.

                              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

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                    if (RegExp.$1 > '12' && RegExp.$3 <= '12' && RegExp.$4 <= '31') {
                                      return RegExp.$4 + ' ' + months[RegExp.$3 - 1] + ' ' + RegExp.$1 + RegExp.$2;
                                    }
                              Severity: Major
                              Found in resources/js/webtrees.js and 1 other location - About 2 hrs to fix
                              resources/js/webtrees.js on lines 214..216

                              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 86.

                              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

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                  if (datestr.match(/^(@#DJALALI@|JALALI)( \d?\d )(\d?\d)( \d?\d?\d?\d)$/)) {
                                    datestr = '@#DJALALI@' + RegExp.$2 + jalali_months[parseInt(RegExp.$3, 10) - 1] + RegExp.$4;
                                  }
                              Severity: Major
                              Found in resources/js/webtrees.js and 1 other location - About 1 hr to fix
                              resources/js/webtrees.js on lines 202..204

                              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 59.

                              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

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                  if (datestr.match(/^(@#DHEBREW@|HEBREW)( \d?\d )(\d?\d)( \d?\d?\d?\d)$/)) {
                                    datestr = '@#DHEBREW@' + RegExp.$2 + hebrew_months[parseInt(RegExp.$3, 10) - 1] + RegExp.$4;
                                  }
                              Severity: Major
                              Found in resources/js/webtrees.js and 1 other location - About 1 hr to fix
                              resources/js/webtrees.js on lines 199..201

                              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 59.

                              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

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                      shown: {
                                        toggle: {
                                          content: this.dataset.wtHidePasswordText,
                                          attr: {
                                            title: this.dataset.wtHidePasswordTitle,
                              Severity: Major
                              Found in resources/js/webtrees.js and 1 other location - About 1 hr to fix
                              resources/js/webtrees.js on lines 999..1007

                              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 57.

                              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

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                      hidden: {
                                        toggle: {
                                          content: this.dataset.wtShowPasswordText,
                                          attr: {
                                            title: this.dataset.wtShowPasswordTitle,
                              Severity: Major
                              Found in resources/js/webtrees.js and 1 other location - About 1 hr to fix
                              resources/js/webtrees.js on lines 990..998

                              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 57.

                              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

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                $.fn.dataTableExt.oSort['text-desc'] = function (x, y) {
                                  return y.localeCompare(x, document.documentElement.lang, { sensitivity: 'base' });
                                };
                              Severity: Major
                              Found in resources/js/webtrees.js and 1 other location - About 1 hr to fix
                              resources/js/webtrees.js on lines 936..938

                              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 56.

                              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

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                $.fn.dataTableExt.oSort['text-asc'] = function (x, y) {
                                  return x.localeCompare(y, document.documentElement.lang, { sensitivity: 'base' });
                                };
                              Severity: Major
                              Found in resources/js/webtrees.js and 1 other location - About 1 hr to fix
                              resources/js/webtrees.js on lines 939..941

                              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 56.

                              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

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                    container.querySelectorAll('.select-' + select.value + ' select').forEach(element => {
                                      element.disabled = false;
                                      if (element.matches('.tom-select')) {
                                        element.tomselect.enable();
                                      }
                              Severity: Minor
                              Found in resources/js/webtrees.js and 1 other location - About 40 mins to fix
                              resources/js/webtrees.js on lines 836..841

                              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 48.

                              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

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                    container.querySelectorAll('.select-record select').forEach(element => {
                                      element.disabled = true;
                                      if (element.matches('.tom-select')) {
                                        element.tomselect.disable();
                                      }
                              Severity: Minor
                              Found in resources/js/webtrees.js and 1 other location - About 40 mins to fix
                              resources/js/webtrees.js on lines 842..847

                              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 48.

                              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

                              Further Reading

                              There are no issues that match your filters.

                              Category
                              Status