dsi-icl/optimise

View on GitHub
packages/optimise-core/src/core/sync.js

Summary

Maintainability
F
4 days
Test Coverage

Function startSync has 232 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    static async startSync(config) {

        if (isSyncing && !config.adminPass)
            return Promise.resolve();

Severity: Major
Found in packages/optimise-core/src/core/sync.js - About 1 day to fix

    File sync.js has 313 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import os from 'os';
    import request from 'request';
    import { getEntry } from '../utils/controller-utils';
    import dbcon from '../utils/db-connection';
    import PatientCore from './patient';
    Severity: Minor
    Found in packages/optimise-core/src/core/sync.js - About 3 hrs to fix

      Function startSync has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          static async startSync(config) {
      
              if (isSyncing && !config.adminPass)
                  return Promise.resolve();
      
      
      Severity: Minor
      Found in packages/optimise-core/src/core/sync.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

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

                      await dbcon()('OPT_KV').where({ key: 'SYNC_STATUS' }).update({
                          value: JSON.stringify({
                              error: {
                                  message: 'Error while processing existing records',
                                  exception: err
      Severity: Major
      Found in packages/optimise-core/src/core/sync.js and 1 other location - About 2 hrs to fix
      packages/optimise-core/src/core/sync.js on lines 157..165

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

      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

                                      await dbcon()('OPT_KV').where({ key: 'SYNC_STATUS' }).update({
                                          value: JSON.stringify({
                                              error: {
                                                  message: 'Synching endpoint is not ready',
                                                  stack: undefined
      Severity: Major
      Found in packages/optimise-core/src/core/sync.js and 1 other location - About 2 hrs to fix
      packages/optimise-core/src/core/sync.js on lines 219..227

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

      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 4 locations. Consider refactoring.
      Open

                  await dbcon()('OPT_KV').where({ key: 'SYNC_STATUS' }).update({
                      value: JSON.stringify({
                          status: 'running',
                          step: 'collecting',
                          syncing: true
      Severity: Major
      Found in packages/optimise-core/src/core/sync.js and 3 other locations - About 2 hrs to fix
      packages/optimise-core/src/core/sync.js on lines 196..203
      packages/optimise-core/src/core/sync.js on lines 230..237
      packages/optimise-core/src/core/sync.js on lines 268..275

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

      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 4 locations. Consider refactoring.
      Open

                  await dbcon()('OPT_KV').where({ key: 'SYNC_STATUS' }).update({
                      value: JSON.stringify({
                          status: 'running',
                          step: 'merging',
                          syncing: true
      Severity: Major
      Found in packages/optimise-core/src/core/sync.js and 3 other locations - About 2 hrs to fix
      packages/optimise-core/src/core/sync.js on lines 184..191
      packages/optimise-core/src/core/sync.js on lines 196..203
      packages/optimise-core/src/core/sync.js on lines 268..275

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

      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 4 locations. Consider refactoring.
      Open

                  await dbcon()('OPT_KV').where({ key: 'SYNC_STATUS' }).update({
                      value: JSON.stringify({
                          status: 'running',
                          step: 'counting',
                          syncing: true
      Severity: Major
      Found in packages/optimise-core/src/core/sync.js and 3 other locations - About 2 hrs to fix
      packages/optimise-core/src/core/sync.js on lines 184..191
      packages/optimise-core/src/core/sync.js on lines 230..237
      packages/optimise-core/src/core/sync.js on lines 268..275

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

      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 4 locations. Consider refactoring.
      Open

                  await dbcon()('OPT_KV').where({ key: 'SYNC_STATUS' }).update({
                      value: JSON.stringify({
                          status: 'running',
                          step: 'linking',
                          syncing: true
      Severity: Major
      Found in packages/optimise-core/src/core/sync.js and 3 other locations - About 2 hrs to fix
      packages/optimise-core/src/core/sync.js on lines 184..191
      packages/optimise-core/src/core/sync.js on lines 196..203
      packages/optimise-core/src/core/sync.js on lines 230..237

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

      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

                                          error: {
                                              message: error ? error.message : (result && result.error ? result.error : 'Unknown error'),
                                              stack: error ? error.stack : (result && result.stack ? result.stack : undefined)
                                          }
      Severity: Major
      Found in packages/optimise-core/src/core/sync.js and 1 other location - About 1 hr to fix
      packages/optimise-core/src/core/sync.js on lines 314..317

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

      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

                                              error: {
                                                  message: error ? error.message : (result && result.error ? result.error : 'Unknown error'),
                                                  stack: error ? error.stack : (result && result.stack ? result.stack : undefined)
                                              }
      Severity: Major
      Found in packages/optimise-core/src/core/sync.js and 1 other location - About 1 hr to fix
      packages/optimise-core/src/core/sync.js on lines 145..148

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

      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

              const key = await dbcon()('OPT_KV').where({ key: 'SYNC_KEY' }).update({
                  value: options.key,
                  updated_at: dbcon().fn.now()
              });
      Severity: Major
      Found in packages/optimise-core/src/core/sync.js and 1 other location - About 1 hr to fix
      packages/optimise-core/src/core/sync.js on lines 47..50

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

      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

              const host = await dbcon()('OPT_KV').where({ key: 'SYNC_HOST' }).update({
                  value: hostURL.href,
                  updated_at: dbcon().fn.now()
              });
      Severity: Major
      Found in packages/optimise-core/src/core/sync.js and 1 other location - About 1 hr to fix
      packages/optimise-core/src/core/sync.js on lines 51..54

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

      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