native/src/utils/DatabaseConnector.ts
File DatabaseConnector.ts
has 766 lines of code (exceeds 250 allowed). Consider refactoring. Open
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'
DatabaseConnector
has 36 functions (exceeds 20 allowed). Consider refactoring. Open
Open
class DatabaseConnector {
constructor() {
this.migrationRoutine().catch(reportError)
}
Function loadPois
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
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
Function mapPoisJson
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
json.map(jsonObject => {
const jsonLocation = jsonObject.location
return new PoiModel({
path: jsonObject.path,
title: jsonObject.title,
Function storePois
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async storePois(pois: Array<PoiModel>, context: DatabaseContext): Promise<void> {
const jsonModels = pois.map(
(poi: PoiModel): ContentPoiJsonType => ({
path: poi.path,
title: poi.title,
Function loadEvents
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
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
Function storeEvents
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async storeEvents(events: Array<EventModel>, context: DatabaseContext): Promise<void> {
const jsonModels = events.map(
(event: EventModel): ContentEventJsonType => ({
path: event.path,
title: event.title,
Function mapEventsJson
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
json.map(jsonObject => {
const jsonDate = jsonObject.date
return new EventModel({
path: jsonObject.path,
title: jsonObject.title,
Function loadCategories
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async loadCategories(context: DatabaseContext): Promise<CategoriesMapModel> {
const path = this.getContentPath('categories', context)
const mapCategoriesJson = (json: ContentCategoryJsonType[]) =>
new CategoriesMapModel(
json.map(
Function storeCategories
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async storeCategories(categoriesMap: CategoriesMapModel, context: DatabaseContext): Promise<void> {
const categoryModels = categoriesMap.toArray()
const jsonModels = categoryModels.map(
(category: CategoryModel): ContentCategoryJsonType => ({
root: category.isRoot(),
Function loadEvents
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
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
- Read upRead up
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"