digitalfabrik/integreat-app

View on GitHub
native/src/utils/DatabaseConnector.ts

Summary

Maintainability
F
4 days
Test Coverage
B
89%

File DatabaseConnector.ts has 766 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { BBox } from 'geojson'
import { map, mapValues } from 'lodash'
import { DateTime } from 'luxon'
import BlobUtil from 'react-native-blob-util'
import { rrulestr } from 'rrule'
Severity: Major
Found in native/src/utils/DatabaseConnector.ts - About 1 day to fix

    DatabaseConnector has 36 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class DatabaseConnector {
      constructor() {
        this.migrationRoutine().catch(reportError)
      }
    
    
    Severity: Minor
    Found in native/src/utils/DatabaseConnector.ts - About 4 hrs to fix

      Function loadPois has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async loadPois(context: DatabaseContext): Promise<Array<PoiModel>> {
          const path = this.getContentPath('pois', context)
          const mapPoisJson = (json: ContentPoiJsonType[]) =>
            json.map(jsonObject => {
              const jsonLocation = jsonObject.location
      Severity: Major
      Found in native/src/utils/DatabaseConnector.ts - About 2 hrs to fix

        Function mapPoisJson has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              json.map(jsonObject => {
                const jsonLocation = jsonObject.location
                return new PoiModel({
                  path: jsonObject.path,
                  title: jsonObject.title,
        Severity: Minor
        Found in native/src/utils/DatabaseConnector.ts - About 1 hr to fix

          Function storePois has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            async storePois(pois: Array<PoiModel>, context: DatabaseContext): Promise<void> {
              const jsonModels = pois.map(
                (poi: PoiModel): ContentPoiJsonType => ({
                  path: poi.path,
                  title: poi.title,
          Severity: Minor
          Found in native/src/utils/DatabaseConnector.ts - About 1 hr to fix

            Function loadEvents has 44 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              async loadEvents(context: DatabaseContext): Promise<Array<EventModel>> {
                const path = this.getContentPath('events', context)
                const mapEventsJson = (json: ContentEventJsonType[]) =>
                  json.map(jsonObject => {
                    const jsonDate = jsonObject.date
            Severity: Minor
            Found in native/src/utils/DatabaseConnector.ts - About 1 hr to fix

              Function storeEvents has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                async storeEvents(events: Array<EventModel>, context: DatabaseContext): Promise<void> {
                  const jsonModels = events.map(
                    (event: EventModel): ContentEventJsonType => ({
                      path: event.path,
                      title: event.title,
              Severity: Minor
              Found in native/src/utils/DatabaseConnector.ts - About 1 hr to fix

                Function mapEventsJson has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      json.map(jsonObject => {
                        const jsonDate = jsonObject.date
                        return new EventModel({
                          path: jsonObject.path,
                          title: jsonObject.title,
                Severity: Minor
                Found in native/src/utils/DatabaseConnector.ts - About 1 hr to fix

                  Function loadCategories has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    async loadCategories(context: DatabaseContext): Promise<CategoriesMapModel> {
                      const path = this.getContentPath('categories', context)
                      const mapCategoriesJson = (json: ContentCategoryJsonType[]) =>
                        new CategoriesMapModel(
                          json.map(
                  Severity: Minor
                  Found in native/src/utils/DatabaseConnector.ts - About 1 hr to fix

                    Function storeCategories has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      async storeCategories(categoriesMap: CategoriesMapModel, context: DatabaseContext): Promise<void> {
                        const categoryModels = categoriesMap.toArray()
                        const jsonModels = categoryModels.map(
                          (category: CategoryModel): ContentCategoryJsonType => ({
                            root: category.isRoot(),
                    Severity: Minor
                    Found in native/src/utils/DatabaseConnector.ts - About 1 hr to fix

                      Function loadEvents has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                        async loadEvents(context: DatabaseContext): Promise<Array<EventModel>> {
                          const path = this.getContentPath('events', context)
                          const mapEventsJson = (json: ContentEventJsonType[]) =>
                            json.map(jsonObject => {
                              const jsonDate = jsonObject.date
                      Severity: Minor
                      Found in native/src/utils/DatabaseConnector.ts - About 55 mins 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

                      There are no issues that match your filters.

                      Category
                      Status