department-of-veterans-affairs/vets-website

View on GitHub
src/applications/vaos/new-appointment/redux/reducer.js

Summary

Maintainability
F
1 wk
Test Coverage

Function formReducer has 664 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export default function formReducer(state = initialState, action) {
  switch (action.type) {
    case FORM_PAGE_OPENED: {
      const { data, schema } = setupFormData(
        state.data,
Severity: Major
Found in src/applications/vaos/new-appointment/redux/reducer.js - About 3 days to fix

    File reducer.js has 796 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /* eslint-disable sonarjs/max-switch-cases */
    import { getDefaultFormState } from '@department-of-veterans-affairs/react-jsonschema-form/lib/utils';
    
    import set from 'platform/utilities/data/set';
    import unset from 'platform/utilities/data/unset';
    Severity: Major
    Found in src/applications/vaos/new-appointment/redux/reducer.js - About 1 day to fix

      Function formReducer has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function formReducer(state = initialState, action) {
        switch (action.type) {
          case FORM_PAGE_OPENED: {
            const { data, schema } = setupFormData(
              state.data,
      Severity: Minor
      Found in src/applications/vaos/new-appointment/redux/reducer.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

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

      function resetFormDataOnTypeOfCareChange(pages, oldData, data) {
        let newPages = pages;
        let newData = data;
      
        if (getTypeOfCare(newData)?.id !== getTypeOfCare(oldData)?.id) {
      Severity: Minor
      Found in src/applications/vaos/new-appointment/redux/reducer.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

      Avoid too many return statements within this function.
      Open

            return {
              ...state,
              data: {
                ...state.data,
                facilityType: action.facilityType,
      Severity: Major
      Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

              return {
                ...state,
                showEligibilityModal: false,
              };
        Severity: Major
        Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                return {
                  ...state,
                  showPodiatryAppointmentUnavailableModal: false,
                };
          Severity: Major
          Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                  return {
                    ...state,
                    requestStatus: FETCH_STATUS.failed,
                  };
            Severity: Major
            Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                    return {
                      ...state,
                      ccProviderPageSortMethod: action.sortMethod,
                      requestLocationStatus,
                    };
              Severity: Major
              Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                      return {
                        ...state,
                        data,
                        pages: {
                          ...state.pages,
                Severity: Major
                Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                        return {
                          ...state,
                          isCCEligible: action.isEligible,
                        };
                  Severity: Major
                  Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return {
                              ...state,
                              currentLocation: {
                                latitude: action.location?.coords.latitude,
                                longitude: action.location?.coords.longitude,
                    Severity: Major
                    Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                            return {
                              ...state,
                              requestStatus: FETCH_STATUS.succeeded,
                              communityCareProviders: {
                                ...state.communityCareProviders,
                      Severity: Major
                      Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                              return {
                                ...state,
                                appointmentSlotsStatus: FETCH_STATUS.loading,
                              };
                        Severity: Major
                        Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                return {
                                  ...state,
                                  requestLocationStatus: FETCH_STATUS.loading,
                                };
                          Severity: Major
                          Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                  return {
                                    ...state,
                                    showEligibilityModal: true,
                                  };
                            Severity: Major
                            Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                    return {
                                      ...state,
                                      data,
                                      pages: {
                                        ...state.pages,
                              Severity: Major
                              Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                      return {
                                        ...state,
                                        data,
                                        pages: {
                                          ...state.pages,
                                Severity: Major
                                Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                        return {
                                          ...state,
                                          pageChangeInProgress: false,
                                          previousPages: updatedPreviousPages,
                                          currentPageKey:
                                  Severity: Major
                                  Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                          return {
                                            ...state,
                                            showPodiatryAppointmentUnavailableModal: true,
                                            pageChangeInProgress: false,
                                          };
                                    Severity: Major
                                    Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                            return {
                                              ...state,
                                              hideUpdateAddressAlert: true,
                                            };
                                      Severity: Major
                                      Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                              return {
                                                ...state,
                                                clinics,
                                                eligibility: {
                                                  ...state.eligibility,
                                        Severity: Major
                                        Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                return {
                                                  ...state,
                                                  eligibilityStatus: FETCH_STATUS.failed,
                                                };
                                          Severity: Major
                                          Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                  return {
                                                    ...state,
                                                    appointmentSlotsStatus: FETCH_STATUS.succeeded,
                                                    availableSlots: action.availableSlots,
                                                    fetchedAppointmentSlotMonths: action.fetchedAppointmentSlotMonths,
                                            Severity: Major
                                            Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                                    return {
                                                      ...state,
                                                      data,
                                                      pages: {
                                                        ...state.pages,
                                              Severity: Major
                                              Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                      return {
                                                        ...state,
                                                        requestLocationStatus: FETCH_STATUS.failed,
                                                      };
                                                Severity: Major
                                                Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                        return {
                                                          ...state,
                                                          eligibilityStatus: FETCH_STATUS.loading,
                                                        };
                                                  Severity: Major
                                                  Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                                    Avoid too many return statements within this function.
                                                    Open

                                                            return {
                                                              ...state,
                                                              selectedCCFacility: action.location,
                                                              ccProviderPageSortMethod: action.sortMethod,
                                                              requestLocationStatus,
                                                    Severity: Major
                                                    Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                                      Avoid too many return statements within this function.
                                                      Open

                                                            return {
                                                              ...state,
                                                              pages: {
                                                                ...state.pages,
                                                                vaFacilityV2: schema,
                                                      Severity: Major
                                                      Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                                        Avoid too many return statements within this function.
                                                        Open

                                                              return {
                                                                ...state,
                                                                ccEnabledSystems: action.ccEnabledSystems,
                                                                parentFacilities: action.parentFacilities,
                                                                parentFacilitiesStatus: FETCH_STATUS.succeeded,
                                                        Severity: Major
                                                        Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                                          Avoid too many return statements within this function.
                                                          Open

                                                                return {
                                                                  ...state,
                                                                  data: {
                                                                    ...state.data,
                                                                    selectedDates: action.selectedDates,
                                                          Severity: Major
                                                          Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                                            Avoid too many return statements within this function.
                                                            Open

                                                                  return {
                                                                    ...state,
                                                                    pages,
                                                                    childFacilitiesStatus: FETCH_STATUS.failed,
                                                                  };
                                                            Severity: Major
                                                            Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                                              Avoid too many return statements within this function.
                                                              Open

                                                                    return {
                                                                      ...state,
                                                                      data,
                                                                      pages: {
                                                                        ...state.pages,
                                                              Severity: Major
                                                              Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                                                Avoid too many return statements within this function.
                                                                Open

                                                                      return {
                                                                        ...state,
                                                                        requestStatus: FETCH_STATUS.loading,
                                                                      };
                                                                Severity: Major
                                                                Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                                                  Avoid too many return statements within this function.
                                                                  Open

                                                                        return {
                                                                          ...state,
                                                                          childFacilitiesStatus: FETCH_STATUS.loading,
                                                                        };
                                                                  Severity: Major
                                                                  Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

                                                                    Avoid too many return statements within this function.
                                                                    Open

                                                                          return {
                                                                            ...state,
                                                                            appointmentSlotsStatus: FETCH_STATUS.failed,
                                                                          };
                                                                    Severity: Major
                                                                    Found in src/applications/vaos/new-appointment/redux/reducer.js - About 30 mins to fix

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

                                                                            if (location && facilities?.length) {
                                                                              const { coords } = location;
                                                                              const { latitude, longitude } = coords;
                                                                      
                                                                              if (latitude && longitude) {
                                                                      Severity: Major
                                                                      Found in src/applications/vaos/new-appointment/redux/reducer.js and 1 other location - About 4 hrs to fix
                                                                      src/applications/vaos/covid-19-vaccine/redux/reducer.js on lines 308..332

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

                                                                      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

                                                                      Identical blocks of code found in 3 locations. Consider refactoring.
                                                                      Open

                                                                            if (hasResidentialCoordinates && facilities.length) {
                                                                              facilities = facilities
                                                                                .map(facility => {
                                                                                  const distanceFromResidentialAddress = distanceBetween(
                                                                                    address.latitude,
                                                                      Severity: Major
                                                                      Found in src/applications/vaos/new-appointment/redux/reducer.js and 2 other locations - About 4 hrs to fix
                                                                      src/applications/vaos/covid-19-vaccine/redux/reducer.js on lines 183..202
                                                                      src/applications/vaos/covid-19-vaccine/redux/reducer.js on lines 486..505

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

                                                                      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

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

                                                                            if (
                                                                              action.direction === 'next' &&
                                                                              action.pageKey !== action.pageKeyNext
                                                                            ) {
                                                                              updatedPreviousPages = {
                                                                      Severity: Major
                                                                      Found in src/applications/vaos/new-appointment/redux/reducer.js and 1 other location - About 1 hr to fix
                                                                      src/applications/vaos/covid-19-vaccine/redux/reducer.js on lines 143..151

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

                                                                      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

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

                                                                            newSchema = set(
                                                                              'properties.vaFacility',
                                                                              {
                                                                                type: 'string',
                                                                                enum: typeOfCareFacilities.map(facility => facility.id),
                                                                      Severity: Minor
                                                                      Found in src/applications/vaos/new-appointment/redux/reducer.js and 1 other location - About 30 mins to fix
                                                                      src/applications/vaos/new-appointment/redux/reducer.js on lines 459..467

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

                                                                      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

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

                                                                            newSchema = set(
                                                                              'properties.vaFacility',
                                                                              {
                                                                                type: 'string',
                                                                                enum: typeOfCareFacilities.map(facility => facility.id),
                                                                      Severity: Minor
                                                                      Found in src/applications/vaos/new-appointment/redux/reducer.js and 1 other location - About 30 mins to fix
                                                                      src/applications/vaos/new-appointment/redux/reducer.js on lines 332..340

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

                                                                      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