instacart/redux-rails

View on GitHub
src/apiReducer.js

Summary

Maintainability
D
2 days
Test Coverage

File apiReducer.js has 327 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { combineReducers } from 'redux'
import {
  apiDefaultState,
  findModel,
  createNewModel,
Severity: Minor
Found in src/apiReducer.js - About 3 hrs to fix

    Avoid too many return statements within this function.
    Open

                return createNewModel({id, cId,
                  metaData: { loadingError: error }
                })
    Severity: Major
    Found in src/apiReducer.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return createNewModel({id,
                    attributes: state.attributes,
                    metaData: { loading: true }
                  })
      Severity: Major
      Found in src/apiReducer.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                  return {
                    ...state,
                    ...{ models: destroyMember({idAttribute, id, state}) }
                  }
        Severity: Major
        Found in src/apiReducer.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                    return createNewCollection({
                      models: setMemberAttributes({data, state, id, cId, metaData: newMeta})
                    })
          Severity: Major
          Found in src/apiReducer.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return createNewModel({id, cId,
                          attributes: currentModel.__prevData
                        })
            Severity: Major
            Found in src/apiReducer.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return resourceConfig.reducer(state, action)
              Severity: Major
              Found in src/apiReducer.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return { 
                              ...state,
                              ...{
                                loading: false,
                                loadingError: error
                Severity: Major
                Found in src/apiReducer.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                            return state
                  Severity: Major
                  Found in src/apiReducer.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return createNewModel({id,
                                  attributes: { ...state.attributes },
                                  metaData: { loadingError: error }
                                })
                    Severity: Major
                    Found in src/apiReducer.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                return createNewCollection({
                                  models: setMemberAttributes({data, state, id, cId, metaData})
                                })
                      Severity: Major
                      Found in src/apiReducer.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                  return {
                                    ...state,
                                    ...{ models: setMemberLoading({id, state, queryParams}) }
                                  }
                        Severity: Major
                        Found in src/apiReducer.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                      return null
                          Severity: Major
                          Found in src/apiReducer.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                      return {
                                        ...state,
                                        ...{ models: setMemberLoading({idAttribute, id, cId, state}) }
                                      }
                            Severity: Major
                            Found in src/apiReducer.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                          return {
                                            ...state,
                                            ...{ models: destroyTempMemeber({cId, state}) }
                                          }
                              Severity: Major
                              Found in src/apiReducer.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                            return {
                                              ...state,
                                              ...{
                                                loading: true,
                                                loadingError: undefined
                                Severity: Major
                                Found in src/apiReducer.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                            return {
                                              ...state,
                                              ...createNewCollection({
                                                models: setMemberAttributes({id, data, state,
                                                  metaData: { loading: false, ...metaData }
                                  Severity: Major
                                  Found in src/apiReducer.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                                return createNewModel({
                                                  metaData: { loading: true, queryParams },
                                                  attributes: state.attributes
                                                })
                                    Severity: Major
                                    Found in src/apiReducer.js - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                                  return createNewModel({id, metaData,
                                                    attributes: { ...state.attributes, ...data }
                                                  })
                                      Severity: Major
                                      Found in src/apiReducer.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                  return {
                                                    ...state,
                                                    ...{ models: setMemberLoadingError({state, id, error}) }
                                                  }
                                        Severity: Major
                                        Found in src/apiReducer.js - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                    return createNewCollection({
                                                      models: setMemberAttributes({cId, state})
                                                    })
                                          Severity: Major
                                          Found in src/apiReducer.js - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                        return createNewModel({id,
                                                          metaData: { loading: true, __prevData},
                                                          attributes: state.attributes
                                                        })
                                            Severity: Major
                                            Found in src/apiReducer.js - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                                        return {
                                                          ...state,
                                                          ...{ models: setMemberLoading({id, state}) }
                                                        }
                                              Severity: Major
                                              Found in src/apiReducer.js - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                            return createNewModel({id,
                                                              attributes: { ...state.attributes, ...data },
                                                              metaData
                                                            })
                                                Severity: Major
                                                Found in src/apiReducer.js - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                            return {
                                                              ...state,
                                                              ...{ models: setMemberLoadingError({state, id, error}) }
                                                            }
                                                  Severity: Major
                                                  Found in src/apiReducer.js - About 30 mins to fix

                                                    Avoid too many return statements within this function.
                                                    Open

                                                              if (destroy && isSingleModel) { return null }
                                                    Severity: Major
                                                    Found in src/apiReducer.js - About 30 mins to fix

                                                      Avoid too many return statements within this function.
                                                      Open

                                                                  return createNewModel({cId})
                                                      Severity: Major
                                                      Found in src/apiReducer.js - About 30 mins to fix

                                                        Avoid too many return statements within this function.
                                                        Open

                                                                    return createNewModel({id, cId,
                                                                      attributes: { ...state.attributes, ...data },
                                                                      metaData
                                                                    })
                                                        Severity: Major
                                                        Found in src/apiReducer.js - About 30 mins to fix

                                                          Avoid too many return statements within this function.
                                                          Open

                                                                    return {
                                                                      ...state,
                                                                      ...{ models: setMemberAttributes({id, data, metaData, state, replaceAttributes: false}) }
                                                                    }
                                                          Severity: Major
                                                          Found in src/apiReducer.js - About 30 mins to fix

                                                            Avoid too many return statements within this function.
                                                            Open

                                                                        return createNewModel({id,
                                                                          attributes: state.attributes,
                                                                          metaData: { loadingError: error }
                                                                        })
                                                            Severity: Major
                                                            Found in src/apiReducer.js - About 30 mins to fix

                                                              Avoid too many return statements within this function.
                                                              Open

                                                                          return createNewModel({id, cId,
                                                                            attributes: { ...currentModel.attributes, ...data },
                                                                            metaData: newMeta
                                                                          })
                                                              Severity: Major
                                                              Found in src/apiReducer.js - About 30 mins to fix

                                                                Avoid too many return statements within this function.
                                                                Open

                                                                          return {
                                                                            ...state,
                                                                            ...{ models: setMemberLoadingError({state, id, cId, error}) }
                                                                          }
                                                                Severity: Major
                                                                Found in src/apiReducer.js - About 30 mins to fix

                                                                  Avoid too many return statements within this function.
                                                                  Open

                                                                            return {
                                                                              ...state,
                                                                              ...{ models: setMemberLoading({idAttribute, id, state}) }
                                                                            }
                                                                  Severity: Major
                                                                  Found in src/apiReducer.js - About 30 mins to fix

                                                                    Avoid too many return statements within this function.
                                                                    Open

                                                                              return {
                                                                                ...state,
                                                                                ...{ models: setMemberLoadingError({state, id, idAttribute, error}) }
                                                                              }
                                                                    Severity: Major
                                                                    Found in src/apiReducer.js - About 30 mins to fix

                                                                      Avoid too many return statements within this function.
                                                                      Open

                                                                                return createNewCollection({
                                                                                  models: setMemberAttributes({data: currentModel.__prevData, state, id, cId})
                                                                                })
                                                                      Severity: Major
                                                                      Found in src/apiReducer.js - About 30 mins to fix

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

                                                                                  if (isSingleModel) {
                                                                                    return createNewModel({id, cId,
                                                                                      attributes: { ...currentModel.attributes, ...data },
                                                                                      metaData: newMeta
                                                                                    })
                                                                        Severity: Minor
                                                                        Found in src/apiReducer.js and 1 other location - About 35 mins to fix
                                                                        src/apiReducer.js on lines 184..189

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

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

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

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

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

                                                                        Refactorings

                                                                        Further Reading

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

                                                                                  if (isSingleModel) {
                                                                                    return createNewModel({id, cId,
                                                                                      attributes: { ...state.attributes, ...data },
                                                                                      metaData
                                                                                    })
                                                                        Severity: Minor
                                                                        Found in src/apiReducer.js and 1 other location - About 35 mins to fix
                                                                        src/apiReducer.js on lines 336..341

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

                                                                        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