HabitatMap/AirCasting

View on GitHub
app/javascript/react/utils/mapParamsHandler.ts

Summary

Maintainability
F
1 wk
Test Coverage

Function useMapParams has 632 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const useMapParams = () => {
  const defaultThresholds = useAppSelector(selectDefaultThresholds);
  const thresholdValues = useAppSelector(selectThresholds);
  const isMobile: boolean = useMobileDetection();
  const [searchParams, setSearchParams] = useSearchParams();
Severity: Major
Found in app/javascript/react/utils/mapParamsHandler.ts - About 3 days to fix

    File mapParamsHandler.ts has 701 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import { debounce } from "lodash";
    import { useCallback, useEffect, useMemo } from "react";
    import { useSearchParams } from "react-router-dom";
    
    import { MAP_CONFIGS } from "../components/Map/mapConfigs";
    Severity: Major
    Found in app/javascript/react/utils/mapParamsHandler.ts - About 1 day to fix

      Function useMapParams has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring.
      Open

      export const useMapParams = () => {
        const defaultThresholds = useAppSelector(selectDefaultThresholds);
        const thresholdValues = useAppSelector(selectThresholds);
        const isMobile: boolean = useMobileDetection();
        const [searchParams, setSearchParams] = useSearchParams();
      Severity: Minor
      Found in app/javascript/react/utils/mapParamsHandler.ts - 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 updateSessionType has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          (selectedSessionType: SessionType) => {
            setUrlParams([
              { key: UrlParamsTypes.sessionType, value: selectedSessionType },
              {
                key: UrlParamsTypes.previousUserSettings,
      Severity: Major
      Found in app/javascript/react/utils/mapParamsHandler.ts - About 2 hrs to fix

        Function setParameterParams has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            (selectedParameter: ParameterType, sensors: Sensor[]) => {
              const sensorData = setSensor(selectedParameter, sensors, sessionType);
              const commonParams = [
                {
                  key: UrlParamsTypes.previousUserSettings,
        Severity: Minor
        Found in app/javascript/react/utils/mapParamsHandler.ts - About 1 hr to fix

          Function setSensorParams has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              (selectedSensor: string, sensors: Sensor[]) => {
                const commonParams = [
                  {
                    key: UrlParamsTypes.previousUserSettings,
                    value: currentUserSettings,
          Severity: Minor
          Found in app/javascript/react/utils/mapParamsHandler.ts - About 1 hr to fix

            Function updateIndoorFilters has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                (isIndoor: string) => {
                  if (isMobile) {
                    setUrlParams([
                      {
                        key: UrlParamsTypes.isIndoor,
            Severity: Minor
            Found in app/javascript/react/utils/mapParamsHandler.ts - About 1 hr to fix

              Function setFilter has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  (key: UrlParamsTypes, value: string) => {
                    if (isMobile) {
                      setUrlParams([
                        {
                          key: key,
              Severity: Minor
              Found in app/javascript/react/utils/mapParamsHandler.ts - About 1 hr to fix

                Function updateIsActive has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    (newIsActive: boolean) => {
                      if (sessionType === SessionTypes.MOBILE) {
                        newIsActive = true;
                      }
                      setUrlParams([
                Severity: Minor
                Found in app/javascript/react/utils/mapParamsHandler.ts - About 1 hr to fix

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

                      (selectedYear: number) => {
                        setUrlParams([
                          {
                            key: UrlParamsTypes.previousUserSettings,
                            value: isMobile ? previousUserSettings : currentUserSettings,
                  Severity: Minor
                  Found in app/javascript/react/utils/mapParamsHandler.ts - About 1 hr to fix

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

                      const updateLimit = useCallback(
                        (newLimit: number) => {
                          setUrlParams([{ key: UrlParamsTypes.limit, value: newLimit.toString() }]);
                        },
                        [setUrlParams]
                    Severity: Major
                    Found in app/javascript/react/utils/mapParamsHandler.ts and 2 other locations - About 1 hr to fix
                    app/javascript/react/utils/mapParamsHandler.ts on lines 159..166
                    app/javascript/react/utils/mapParamsHandler.ts on lines 171..181

                    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

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

                      const updateOffset = useCallback(
                        (newOffset: number) => {
                          setUrlParams([
                            { key: UrlParamsTypes.offset, value: newOffset.toString() },
                          ]);
                    Severity: Major
                    Found in app/javascript/react/utils/mapParamsHandler.ts and 2 other locations - About 1 hr to fix
                    app/javascript/react/utils/mapParamsHandler.ts on lines 142..147
                    app/javascript/react/utils/mapParamsHandler.ts on lines 171..181

                    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

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

                      const updateFetchedSessions = useCallback(
                        (newFetchedSessions: number) => {
                          setUrlParams([
                            {
                              key: UrlParamsTypes.fetchedSessions,
                    Severity: Major
                    Found in app/javascript/react/utils/mapParamsHandler.ts and 2 other locations - About 1 hr to fix
                    app/javascript/react/utils/mapParamsHandler.ts on lines 142..147
                    app/javascript/react/utils/mapParamsHandler.ts on lines 159..166

                    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

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

                            {
                              key: UrlParamsTypes.currentUserSettings,
                              value: isMobile
                                ? UserSettings.FiltersView
                                : currentUserSettings === UserSettings.CrowdMapView
                    Severity: Major
                    Found in app/javascript/react/utils/mapParamsHandler.ts and 5 other locations - About 40 mins to fix
                    app/javascript/react/components/SessionFilters/CustomParameterFilter.tsx on lines 72..79
                    app/javascript/react/components/SessionFilters/CustomSensorFilter.tsx on lines 68..75
                    app/javascript/react/utils/mapParamsHandler.ts on lines 308..315
                    app/javascript/react/utils/mapParamsHandler.ts on lines 548..555
                    app/javascript/react/utils/mapParamsHandler.ts on lines 647..654

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 48.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

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

                            {
                              key: UrlParamsTypes.currentUserSettings,
                              value: isMobile
                                ? UserSettings.FiltersView
                                : currentUserSettings === UserSettings.CrowdMapView
                    Severity: Major
                    Found in app/javascript/react/utils/mapParamsHandler.ts and 5 other locations - About 40 mins to fix
                    app/javascript/react/components/SessionFilters/CustomParameterFilter.tsx on lines 72..79
                    app/javascript/react/components/SessionFilters/CustomSensorFilter.tsx on lines 68..75
                    app/javascript/react/utils/mapParamsHandler.ts on lines 308..315
                    app/javascript/react/utils/mapParamsHandler.ts on lines 548..555
                    app/javascript/react/utils/mapParamsHandler.ts on lines 592..599

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 48.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

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

                            {
                              key: UrlParamsTypes.currentUserSettings,
                              value: isMobile
                                ? UserSettings.FiltersView
                                : currentUserSettings === UserSettings.CrowdMapView
                    Severity: Major
                    Found in app/javascript/react/utils/mapParamsHandler.ts and 5 other locations - About 40 mins to fix
                    app/javascript/react/components/SessionFilters/CustomParameterFilter.tsx on lines 72..79
                    app/javascript/react/components/SessionFilters/CustomSensorFilter.tsx on lines 68..75
                    app/javascript/react/utils/mapParamsHandler.ts on lines 308..315
                    app/javascript/react/utils/mapParamsHandler.ts on lines 592..599
                    app/javascript/react/utils/mapParamsHandler.ts on lines 647..654

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 48.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

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

                            {
                              key: UrlParamsTypes.currentUserSettings,
                              value: isMobile
                                ? UserSettings.FiltersView
                                : currentUserSettings === UserSettings.CrowdMapView
                    Severity: Major
                    Found in app/javascript/react/utils/mapParamsHandler.ts and 5 other locations - About 40 mins to fix
                    app/javascript/react/components/SessionFilters/CustomParameterFilter.tsx on lines 72..79
                    app/javascript/react/components/SessionFilters/CustomSensorFilter.tsx on lines 68..75
                    app/javascript/react/utils/mapParamsHandler.ts on lines 548..555
                    app/javascript/react/utils/mapParamsHandler.ts on lines 592..599
                    app/javascript/react/utils/mapParamsHandler.ts on lines 647..654

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 48.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    There are no issues that match your filters.

                    Category
                    Status