timgabets/electron-atm

View on GitHub
src/controllers/atm.js

Summary

Maintainability
F
1 wk
Test Coverage

File atm.js has 761 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const StatesService = require('atm-states');
const ScreensService = require('atm-screens');
const FITsService = require('atm-fits');
const CryptoService = require('../services/crypto.js');
const DisplayService = require('../services/display.js');
Severity: Major
Found in src/controllers/atm.js - About 1 day to fix

ATM has 48 functions (exceeds 20 allowed). Consider refactoring.
Open

class ATM {
  constructor(settings, log){
    this.settings = settings;
    this.log = log;
    this.trace = new Trace();
Severity: Minor
Found in src/controllers/atm.js - About 6 hrs to fix

Function processNumericButtonPressed has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

  processNumericButtonPressed(button){
    switch(this.current_state.get('type')){
    case 'B':
      this.PIN_buffer += button;
      if(this.PIN_buffer.length >= this.FITs.getMaxPINLength(this.card.number) || this.PIN_buffer.length >= 6 )
Severity: Minor
Found in src/controllers/atm.js - About 3 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 processState has 69 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  processState(state_number){
    let state = this.states.get(state_number);
    let next_state = null;

    do{
Severity: Major
Found in src/controllers/atm.js - About 2 hrs to fix

Function processState has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  processState(state_number){
    let state = this.states.get(state_number);
    let next_state = null;

    do{
Severity: Minor
Found in src/controllers/atm.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 processNumericButtonPressed has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  processNumericButtonPressed(button){
    switch(this.current_state.get('type')){
    case 'B':
      this.PIN_buffer += button;
      if(this.PIN_buffer.length >= this.FITs.getMaxPINLength(this.card.number) || this.PIN_buffer.length >= 6 )
Severity: Minor
Found in src/controllers/atm.js - About 1 hr to fix

Function processTransactionRequestState has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  processTransactionRequestState(state){
    this.display.setScreenByNumber(state.get('screen_number'));

    let request = {
      message_class: 'Unsolicited',
Severity: Minor
Found in src/controllers/atm.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 setFDKsActiveMask has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  setFDKsActiveMask(mask){
    if(mask.length <= 3 && mask.length !== 0){
      // 1. mask is a number from 000 to 255, represented as string
      if(mask > 255){
        this.log.error('Invalid FDK mask: ' + mask);
Severity: Minor
Found in src/controllers/atm.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 processTransactionRequestState has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  processTransactionRequestState(state){
    this.display.setScreenByNumber(state.get('screen_number'));

    let request = {
      message_class: 'Unsolicited',
Severity: Minor
Found in src/controllers/atm.js - About 1 hr to fix

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

  processBackspaceButtonPressed(){
    switch(this.current_state.get('type')){
    case 'B':
      this.PIN_buffer = this.PIN_buffer.slice(0, -1);
      this.display.insertText(this.PIN_buffer, '*');
Severity: Minor
Found in src/controllers/atm.js - About 1 hr to fix

Function processStateX has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  processStateX(state, extension_state){
    this.display.setScreenByNumber(state.get('screen_number'));
    this.setFDKsActiveMask(state.get('FDK_active_mask'));

    let button = this.buttons_pressed.shift();
Severity: Minor
Found in src/controllers/atm.js - About 1 hr to fix

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

  processFDKButtonPressed(button){
    // log.info(button + ' button pressed');
    switch(this.current_state.get('type')){
    case 'B':
      if (button === 'A' && this.PIN_buffer.length >= 4)
Severity: Minor
Found in src/controllers/atm.js - About 1 hr to fix

Function processCustomizationCommand has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  processCustomizationCommand(data){
    switch(data.message_identifier){
    case 'Screen Data load':
      if(this.screens.add(data.screens))
        return this.replySolicitedStatus('Ready'); 
Severity: Minor
Found in src/controllers/atm.js - About 1 hr to fix

Function processInformationEntryState has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  processInformationEntryState(state){
    this.display.setScreenByNumber(state.get('screen_number'));
    let active_mask = '0';
    [ state.get('FDK_A_next_state'),
      state.get('FDK_B_next_state'),
Severity: Minor
Found in src/controllers/atm.js - About 1 hr to fix

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

  processCustomizationCommand(data){
    switch(data.message_identifier){
    case 'Screen Data load':
      if(this.screens.add(data.screens))
        return this.replySolicitedStatus('Ready'); 
Severity: Minor
Found in src/controllers/atm.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 getTerminalStateReply has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  getTerminalStateReply(command_code){
    let reply = {};

    if(command_code)
      reply.terminal_command = command_code;
Severity: Minor
Found in src/controllers/atm.js - About 1 hr to fix

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

  processStateX(state, extension_state){
    this.display.setScreenByNumber(state.get('screen_number'));
    this.setFDKsActiveMask(state.get('FDK_active_mask'));

    let button = this.buttons_pressed.shift();
Severity: Minor
Found in src/controllers/atm.js - 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

Avoid too many return statements within this function.
Open

        return this.replySolicitedStatus('Ready');
Severity: Major
Found in src/controllers/atm.js - About 30 mins to fix

Avoid too many return statements within this function.
Open

        return this.replySolicitedStatus('Command Reject');
Severity: Major
Found in src/controllers/atm.js - About 30 mins to fix

Avoid too many return statements within this function.
Open

        return this.replySolicitedStatus('Command Reject');
Severity: Major
Found in src/controllers/atm.js - About 30 mins to fix

Avoid too many return statements within this function.
Open

      return this.replySolicitedStatus('Command Reject');
Severity: Major
Found in src/controllers/atm.js - About 30 mins to fix

Avoid too many return statements within this function.
Open

        return this.replySolicitedStatus('Ready');
Severity: Major
Found in src/controllers/atm.js - About 30 mins to fix

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

      case 'Y':
        (state.get('extension_state') !== '255' && state.get('extension_state') !== '000') ? next_state = this.processStateY(state, this.states.get(state.get('extension_state'))) : next_state = this.processStateY(state);
        break;
Severity: Major
Found in src/controllers/atm.js and 1 other location - About 2 hrs to fix
src/controllers/atm.js on lines 803..805

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

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

      case 'X':
        (state.get('extension_state') !== '255' && state.get('extension_state') !== '000') ? next_state = this.processStateX(state, this.states.get(state.get('extension_state'))) : next_state = this.processStateX(state);
        break;
Severity: Major
Found in src/controllers/atm.js and 1 other location - About 2 hrs to fix
src/controllers/atm.js on lines 807..809

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

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

        case '3': // Display data as keyed in. Store data in general-purpose Buffer B
          if(this.buffer_B.length < 32){
            this.buffer_B += button;

            buffer = this.buffer_B;
Severity: Major
Found in src/controllers/atm.js and 1 other location - About 1 hr to fix
src/controllers/atm.js on lines 1083..1092

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

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

        case '1': // Display data as keyed in. Store data in general-purpose Buffer C
          if(this.buffer_C.length < 32){
            this.buffer_C += button;

            buffer = this.buffer_C;
Severity: Major
Found in src/controllers/atm.js and 1 other location - About 1 hr to fix
src/controllers/atm.js on lines 1094..1103

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

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

        case '3': // Display data as keyed in. Store data in general-purpose Buffer B
          this.buffer_B = this.buffer_B.substr(0, this.buffer_B.length - 1);
          buffer = this.buffer_B;
          break;
Severity: Minor
Found in src/controllers/atm.js and 1 other location - About 55 mins to fix
src/controllers/atm.js on lines 1015..1018

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

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

        case '1': // Display data as keyed in. Store data in general-purpose Buffer C
          this.buffer_C = this.buffer_C.substr(0, this.buffer_C.length - 1);
          buffer = this.buffer_C;
          break;
Severity: Minor
Found in src/controllers/atm.js and 1 other location - About 55 mins to fix
src/controllers/atm.js on lines 1024..1027

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

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

    case 'Screen Data load':
      if(this.screens.add(data.screens))
        return this.replySolicitedStatus('Ready'); 
      else
        return this.replySolicitedStatus('Command Reject');
Severity: Minor
Found in src/controllers/atm.js and 2 other locations - About 35 mins to fix
src/controllers/atm.js on lines 212..216
src/controllers/atm.js on lines 218..222

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

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

    case 'State Tables load':
      if(this.states.add(data.states))
        return this.replySolicitedStatus('Ready'); 
      else
        return this.replySolicitedStatus('Command Reject');
Severity: Minor
Found in src/controllers/atm.js and 2 other locations - About 35 mins to fix
src/controllers/atm.js on lines 206..210
src/controllers/atm.js on lines 218..222

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

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

    case 'FIT Data load':
      if(this.FITs.add(data.FITs))
        return this.replySolicitedStatus('Ready');
      else
        return this.replySolicitedStatus('Command Reject');
Severity: Minor
Found in src/controllers/atm.js and 2 other locations - About 35 mins to fix
src/controllers/atm.js on lines 206..210
src/controllers/atm.js on lines 212..216

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

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