test-app/app/controllers/calculator.js
import { later } from '@ember/runloop';import Controller from '@ember/controller';import { computed as c } from '@ember/object';import { action } from '@ember/object'; export default Controller.extend({ init() { this._super(...arguments); this.setProperties({ result: '', expression: '', op: '', loading: false, }); }, stack: c({ get() { return []; }, }), Function `keyPress` has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Function `keyPress` has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. keyPress: action(function (key, asyncOp) { let exec = () => { let result = this.expression; let stack = this.stack; let op = this.op; switch (key) { case '+': case '-': case '=': stack.push(parseInt(op + result)); this.set('result', result); this.set('expression', ''); break; default: this.set('expression', result + key.toString()); break; } Similar blocks of code found in 2 locations. Consider refactoring. switch (key) { case '-': this.set('op', '-'); break; case '=': result = stack.reduce((result, value) => result + value, 0); this.set('expression', result.toString()); break; } }; if (asyncOp) { this.set('loading', true); later(() => { this.set('loading', false); exec(); }, 50); } else { exec(); } }),});