GladysProject/Gladys

View on GitHub
front/src/actions/gateway.js

Summary

Maintainability
F
1 wk
Test Coverage

Function createActions has 443 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function createActions(store) {
  const actions = {
    async getStatus(state) {
      store.setState({
        gatewayGetStatusStatus: RequestStatus.Getting
Severity: Major
Found in front/src/actions/gateway.js - About 2 days to fix

    Function createActions has a Cognitive Complexity of 68 (exceeds 5 allowed). Consider refactoring.
    Open

    function createActions(store) {
      const actions = {
        async getStatus(state) {
          store.setState({
            gatewayGetStatusStatus: RequestStatus.Getting
    Severity: Minor
    Found in front/src/actions/gateway.js - About 1 day 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

    File gateway.js has 452 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import get from 'get-value';
    import update from 'immutability-helper';
    import { route } from 'preact-router';
    import { RequestStatus, LoginStatus } from '../utils/consts';
    import { validateEmail } from '../utils/validator';
    Severity: Minor
    Found in front/src/actions/gateway.js - About 6 hrs to fix

      actions has 29 functions (exceeds 20 allowed). Consider refactoring.
      Open

        const actions = {
          async getStatus(state) {
            store.setState({
              gatewayGetStatusStatus: RequestStatus.Getting
            });
      Severity: Minor
      Found in front/src/actions/gateway.js - About 3 hrs to fix

        Function login has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            async login(state, e) {
              if (e) {
                e.preventDefault();
              }
              if (!validateEmail(state.gatewayLoginEmail)) {
        Severity: Minor
        Found in front/src/actions/gateway.js - About 1 hr to fix

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

              async waitForRestoreToFinish(state) {
                try {
                  const restoreStatus = await state.httpClient.get('/api/v1/gateway/backup/restore/status');
                  if (restoreStatus.restore_in_progress) {
                    setTimeout(() => {
          Severity: Minor
          Found in front/src/actions/gateway.js - About 1 hr to fix

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

                async loginTwoFactor(state, e) {
                  if (e) {
                    e.preventDefault();
                  }
                  store.setState({
            Severity: Minor
            Found in front/src/actions/gateway.js - About 1 hr to fix

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

                  async getStatus(state) {
                    store.setState({
                      gatewayGetStatusStatus: RequestStatus.Getting
                    });
                    try {
              Severity: Major
              Found in front/src/actions/gateway.js and 7 other locations - About 3 hrs to fix
              front/src/actions/gateway.js on lines 216..231
              front/src/actions/gateway.js on lines 232..247
              front/src/actions/map.js on lines 5..22
              front/src/actions/map.js on lines 23..38
              front/src/actions/session.js on lines 6..21
              front/src/actions/system.js on lines 49..64
              front/src/routes/integration/all/bluetooth/setup-page/actions.js on lines 13..28

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

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

                  async getBackups(state) {
                    store.setState({
                      gatewayGetBackupsStatus: RequestStatus.Getting
                    });
                    try {
              Severity: Major
              Found in front/src/actions/gateway.js and 7 other locations - About 3 hrs to fix
              front/src/actions/gateway.js on lines 10..25
              front/src/actions/gateway.js on lines 216..231
              front/src/actions/map.js on lines 5..22
              front/src/actions/map.js on lines 23..38
              front/src/actions/session.js on lines 6..21
              front/src/actions/system.js on lines 49..64
              front/src/routes/integration/all/bluetooth/setup-page/actions.js on lines 13..28

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

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

                  async getInstanceKeys(state) {
                    store.setState({
                      gatewayGetInstanceKeysStatus: RequestStatus.Getting
                    });
                    try {
              Severity: Major
              Found in front/src/actions/gateway.js and 7 other locations - About 3 hrs to fix
              front/src/actions/gateway.js on lines 10..25
              front/src/actions/gateway.js on lines 232..247
              front/src/actions/map.js on lines 5..22
              front/src/actions/map.js on lines 23..38
              front/src/actions/session.js on lines 6..21
              front/src/actions/system.js on lines 49..64
              front/src/routes/integration/all/bluetooth/setup-page/actions.js on lines 13..28

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

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

                    try {
                      const gatewayUsersKeys = await state.httpClient.get('/api/v1/gateway/key');
                      store.setState({
                        gatewayUsersKeys,
                        gatewayGetKeysStatus: RequestStatus.Success
              Severity: Major
              Found in front/src/actions/gateway.js and 2 other locations - About 2 hrs to fix
              front/src/actions/gateway.js on lines 38..59
              front/src/actions/login/loginGateway.js on lines 38..64

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

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

                    try {
                      const gatewayLoginResults = await state.httpClient.post('/api/v1/gateway/login', {
                        email: state.gatewayLoginEmail,
                        password: state.gatewayLoginPassword
                      });
              Severity: Major
              Found in front/src/actions/gateway.js and 2 other locations - About 2 hrs to fix
              front/src/actions/gateway.js on lines 174..191
              front/src/actions/login/loginGateway.js on lines 38..64

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

              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