joendres/nextcloud-filelink

View on GitHub

Showing 34 of 34 total issues

Function handleFormData has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
Open

async function handleFormData() {

    sanitizeInput();

    // If user typed new password, username or URL the token is likely not valid any more
Severity: Minor
Found in src/prefspane/management.js - About 6 hrs to fix

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 updateCapabilities has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

    async updateCapabilities() {
        const data = await this._doApiCall(apiUrlCapabilities);
        if (!data._failed && data.capabilities) {
            // Don't test data.capabilities.files_sharing.api_enabled because the next line contains it all
            // Is public sharing enabled?
Severity: Minor
Found in src/lib/cloudconnection.js - About 4 hrs to fix

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 handleFormData has 102 lines of code (exceeds 25 allowed). Consider refactoring.
Open

async function handleFormData() {

    sanitizeInput();

    // If user typed new password, username or URL the token is likely not valid any more
Severity: Major
Found in src/prefspane/management.js - About 4 hrs to fix

    File cloudconnection.js has 331 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    //#region  Configurable options and useful constants
    const apiUrlBase = "ocs/v1.php";
    const apiUrlUserInfo = "/cloud/users/";
    const apiUrlUserID = "/cloud/user";
    const apiUrlShares = "/apps/files_sharing/api/v1/shares";
    Severity: Minor
    Found in src/lib/cloudconnection.js - About 3 hrs to fix

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

                      try {
                          const u = new URL(data.capabilities.password_policy.api.validate);
                          if (u.host === (new URL(this.serverUrl)).host) {
                              this._password_validate_url = u.origin + u.pathname;
                          }
      Severity: Major
      Found in src/lib/cloudconnection.js and 1 other location - About 2 hrs to fix
      src/lib/cloudconnection.js on lines 206..211

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

      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

                      try {
                          const u = new URL(data.capabilities.password_policy.api.generate);
                          if (u.host === (new URL(this.serverUrl)).host) {
                              this._password_generate_url = u.origin + u.pathname;
                          }
      Severity: Major
      Found in src/lib/cloudconnection.js and 1 other location - About 2 hrs to fix
      src/lib/cloudconnection.js on lines 200..205

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

      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

      File management.js has 268 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      const accountId = new URL(location.href).searchParams.get("accountId");
      const ncc = new CloudConnection(accountId);
      
      loadFormData()
          .then(updateHeader)
      Severity: Minor
      Found in src/prefspane/management.js - About 2 hrs to fix

        Function updateCapabilities has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            async updateCapabilities() {
                const data = await this._doApiCall(apiUrlCapabilities);
                if (!data._failed && data.capabilities) {
                    // Don't test data.capabilities.files_sharing.api_enabled because the next line contains it all
                    // Is public sharing enabled?
        Severity: Major
        Found in src/lib/cloudconnection.js - About 2 hrs to fix

          Function updateCloudInfo has 47 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async function updateCloudInfo() {
                  let answer = await ncc.updateUserId();
                  ncc.laststatus = null;
                  if (answer._failed) {
                      // If login failed, we might be using an app token which requires a lowercase user name
          Severity: Minor
          Found in src/prefspane/management.js - About 1 hr to fix

            Function updateFreeSpaceInfo has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                async updateFreeSpaceInfo() {
                    let spaceRemaining = -1;
                    let spaceUsed = -1;
            
                    const data = await this._doApiCall(apiUrlUserInfo + this.userId);
            Severity: Minor
            Found in src/lib/cloudconnection.js - About 1 hr to fix

            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 showErrors has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

            function showErrors() {
                if (ncc.laststatus) {
                    popup.error(ncc.laststatus);
                } else if (false === ncc.public_shares_enabled) {
                    popup.error('sharing_off');
            Severity: Minor
            Found in src/prefspane/management.js - About 1 hr to fix

            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 updateStatusDisplay has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

            function updateStatusDisplay(uploads) {
                // Remove extra rows
                while (status_lines.rows.length > uploads.size) {
                    status_lines.deleteRow(-1);
                }
            Severity: Minor
            Found in src/progress/progress.js - About 1 hr to fix

            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 _doApiCall has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                async _doApiCall(suburl, method = 'GET', additional_headers = undefined, body = undefined) {
                    let url;
                    if (suburl.startsWith(this.serverUrl)) {
                        url = suburl;
                    } else {
            Severity: Minor
            Found in src/lib/cloudconnection.js - About 1 hr to fix

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

                  async _doUpload(uploadId, fileName, fileObject) {
                      // Is the file bigger than the maximum size for WebDAV?
                      attachmentStatus.get(uploadId).set_status('checkingsize');
                      if (fileObject.size > DAV_MAX_FILE_SIZE) {
                          attachmentStatus.get(uploadId).fail();
              Severity: Minor
              Found in src/lib/davuploader.js - About 1 hr to fix

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

                            if ("free" in data.quota) {
                                const free = parseInt(data.quota.free);
                                spaceRemaining = free >= 0 && free <= Number.MAX_SAFE_INTEGER ? free : -1;
                            }
                Severity: Major
                Found in src/lib/cloudconnection.js and 1 other location - About 1 hr to fix
                src/lib/cloudconnection.js on lines 144..147

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

                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 ("used" in data.quota) {
                                const used = parseInt(data.quota.used);
                                spaceUsed = used >= 0 && used <= Number.MAX_SAFE_INTEGER ? used : -1;
                            }
                Severity: Major
                Found in src/lib/cloudconnection.js and 1 other location - About 1 hr to fix
                src/lib/cloudconnection.js on lines 140..143

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

                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

                Function _doUpload has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                    async _doUpload(uploadId, fileName, fileObject) {
                        // Is the file bigger than the maximum size for WebDAV?
                        attachmentStatus.get(uploadId).set_status('checkingsize');
                        if (fileObject.size > DAV_MAX_FILE_SIZE) {
                            attachmentStatus.get(uploadId).fail();
                Severity: Minor
                Found in src/lib/davuploader.js - About 1 hr to fix

                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 _doApiCall has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                    async _doApiCall(suburl, method = 'GET', additional_headers = undefined, body = undefined) {
                        let url;
                        if (suburl.startsWith(this.serverUrl)) {
                            url = suburl;
                        } else {
                Severity: Minor
                Found in src/lib/cloudconnection.js - About 1 hr to fix

                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 fill_status_row has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                function fill_status_row(status, row) {
                    status_lines.rows[row].cells[0].textContent = status.filename;
                
                    const status_cell = status_lines.rows[row].cells[1];
                    if (status.error) {
                Severity: Minor
                Found in src/progress/progress.js - About 1 hr to fix

                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 updateGauge has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                async function updateGauge() {
                    freespaceGauge.style.visibility = "hidden";
                    // Only show gauge if relevant form data match the account data
                    if (username.value === ncc.username && serverUrl.value === ncc.serverUrl) {
                        let theAccount = await messenger.cloudFile.getAccount(accountId);
                Severity: Minor
                Found in src/prefspane/management.js - About 1 hr to fix
                  Severity
                  Category
                  Status
                  Source
                  Language