laundree/laundree

View on GitHub

Showing 37 of 96 total issues

File user.js has 411 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// @flow

import { Handler, HandlerLibrary } from './handler'
import TokenHandler from './token'
import BookingHandler from './booking'
Severity: Minor
Found in src/handlers/user.js - About 5 hrs to fix

UserHandler has 41 functions (exceeds 20 allowed). Consider refactoring.
Open

export default class UserHandler extends Handler<UserModel, User, RestUser> {
  static lib = new UserHandlerLibrary()
  lib = UserHandler.lib

  static restSummary (i: ObjectId | UserHandler) {
Severity: Minor
Found in src/handlers/user.js - About 5 hrs to fix

LaundryHandler has 39 functions (exceeds 20 allowed). Consider refactoring.
Open

export default class LaundryHandler extends Handler<LaundryModel, ReduxLaundry, RestLaundry> {
  static restSummary (i: ObjectId | LaundryHandler) {
    const id = Handler.handlerOrObjectIdToString(i)
    return {id, href: restUrlPrefix + id}
  }
Severity: Minor
Found in src/handlers/laundry.js - About 5 hrs to fix

File socket_io.js has 381 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// @flow
import connectMongoose from '../db/mongoose'
import socketIo from 'socket.io'
import UserHandler from '../handlers/user'
import LaundryHandler from '../handlers/laundry'
Severity: Minor
Found in src/websocket/socket_io.js - About 5 hrs to fix

File laundry.js has 356 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// @flow
import LaundryModel from '../db/models/laundry'
import type { LaundryRules } from '../db/models/laundry'
import { Handler, HandlerLibrary } from './handler'
import UserHandler from './user'
Severity: Minor
Found in src/handlers/laundry.js - About 4 hrs to fix

Function setupAdminFunctions has 55 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function setupAdminFunctions (socket) {
  debug('Adding admin functions')
  defineSocketFunction(
    socket,
    'listLaundries',
Severity: Major
Found in src/websocket/socket_io.js - About 2 hrs to fix

Function validate has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

  validate (props: ValidationElementProps<V> = this.props): boolean {
    const value = props.trim && typeof props.value === 'string'
      ? props.value.trim()
      : props.value
    if (props.equal !== undefined) return props.equal === value
Severity: Minor
Found in src/react/validation/ValidationElement.js - About 2 hrs 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 setupFunctions has 52 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function setupFunctions (socket) {
  defineLaundrySocketFunction(
    socket,
    'listBookingsInTime',
    async (laundry, fromO, toO) => {
Severity: Major
Found in src/websocket/socket_io.js - About 2 hrs to fix

Function createBookingAsync has 45 lines of code (exceeds 25 allowed). Consider refactoring.
Open

async function createBookingAsync (subjects, params) {
  const {machine, laundry, currentUser, createBookingBody} = api
    .assertSubjects({
      machine: subjects.machine,
      currentUser: subjects.currentUser,
Severity: Minor
Found in src/api/controllers/bookings.js - About 1 hr to fix

Function setupUser has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function setupUser (socket, userUpdateEmitter, u: ?UserHandler) {
  const user = u
  if (!user) {
    debug('Found no user, will not setup')
    return
Severity: Minor
Found in src/websocket/socket_io.js - About 1 hr to fix

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

export async function createInvitePdf (laundryId: string, code: string, locale: LocaleType) {
  const doc = new PdfDocument({size: [2 * 240, 2 * 320]})
  const link = `https://laundree.io/s/${laundryId}/${code}`
  const logoWidth = 150
  const logoX = (doc.page.width - logoWidth) / 2
Severity: Minor
Found in src/utils/pdf.js - About 1 hr to fix

Function updateBookingAsync has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

async function updateBookingAsync (subjects, params) {
  const {booking, laundry, currentUser, updateBookingBody} = api
    .assertSubjects({
      booking: subjects.booking,
      currentUser: subjects.currentUser,
Severity: Minor
Found in src/api/controllers/bookings.js - About 1 hr to fix

Function authenticateSocket has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

async function authenticateSocket (socket): Promise<?UserHandler> {
  debug('Authenticating user')
  const {userId, token, jwt} = socket.handshake.query || {} // Authenticate token from query
  if (userId && token) {
    debug('Got userId and token', userId, token)
Severity: Minor
Found in src/websocket/socket_io.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

Function createBookingAsync has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

async function createBookingAsync (subjects, params) {
  const {machine, laundry, currentUser, createBookingBody} = api
    .assertSubjects({
      machine: subjects.machine,
      currentUser: subjects.currentUser,
Severity: Minor
Found in src/api/controllers/bookings.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

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

async function authenticateSocket (socket): Promise<?UserHandler> {
  debug('Authenticating user')
  const {userId, token, jwt} = socket.handshake.query || {} // Authenticate token from query
  if (userId && token) {
    debug('Got userId and token', userId, token)
Severity: Minor
Found in src/websocket/socket_io.js - About 1 hr to fix

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

async function basic (req, authOrSecDef, scopesOrApiKey, callback) {
  const authHeader = req.header('authorization')
  const match = authHeader && authHeader.match(/^Basic (.+)$/)
  const token = match && match[1]
  debug('Verifying token %s', token)
Severity: Minor
Found in src/api/app.js - About 1 hr to fix

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

async function pullSubjects (params: ParsedParams, req: Request): Promise<Subjects> {
  const currentUserId = req.userId || null
  const currentUser = await (currentUserId && UserHandler.lib.findFromId(currentUserId))
  const [user, machine, token, invite, laundry, booking] = await Promise.all([
    params.userId ? pullSubject(params.userId, UserHandler) : null,
Severity: Minor
Found in src/api/helper.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

Function inviteUserByEmailAsync has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

async function inviteUserByEmailAsync (subs, params) {
  const {laundry, inviteUserByEmailBody} = api.assertSubjects({
    laundry: subs.laundry,
    inviteUserByEmailBody: params.inviteUserByEmailBody
  })
Severity: Minor
Found in src/api/controllers/laundries.js - About 1 hr to fix

Function createInitialEvents has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

export async function createInitialEvents (currentUser: ?User, successFlash: string[] = [], errorFlash: string[] = [], locale: LocaleType = 'en', token: string = '', statistics: {userCount: number, bookingCount: number}) {
Severity: Minor
Found in src/web/redux.js - About 45 mins to fix

Function updateBookingAsync has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

async function updateBookingAsync (subjects, params) {
  const {booking, laundry, currentUser, updateBookingBody} = api
    .assertSubjects({
      booking: subjects.booking,
      currentUser: subjects.currentUser,
Severity: Minor
Found in src/api/controllers/bookings.js - About 45 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

Severity
Category
Status
Source
Language