aureooms/js-integer

View on GitHub
src/Integer.js

Summary

Maintainability
D
3 days
Test Coverage
A
100%

Integer has 77 functions (exceeds 20 allowed). Consider refactoring.
Open

export class Integer {
    constructor(base, is_negative, limbs) {
        this._base = base;
        this._is_negative = is_negative;
        this._limbs = limbs;
Severity: Major
Found in src/Integer.js - About 1 day to fix

    File Integer.js has 434 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import {DEFAULT_DISPLAY_BASE} from './DEFAULT_DISPLAY_BASE.js';
    import {ZeroDivisionError} from './ZeroDivisionError.js';
    
    import {ValueError} from '@aureooms/js-error';
    
    
    Severity: Minor
    Found in src/Integer.js - About 6 hrs to fix

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

          egcd(other) {
              const r = this._base;
              const a = this._limbs;
              const b = other._limbs_in_base(r);
              const [
      Severity: Minor
      Found in src/Integer.js - About 1 hr to fix

        Function divmod has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            divmod(other) {
                if (other.iszero()) throw new ZeroDivisionError('Integer division by zero'); // Optimize
        
                const quotient_is_negative = this._is_negative ^ other._is_negative;
                const r = this._base;
        Severity: Minor
        Found in src/Integer.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 divmod has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            divmod(other) {
                if (other.iszero()) throw new ZeroDivisionError('Integer division by zero'); // Optimize
        
                const quotient_is_negative = this._is_negative ^ other._is_negative;
                const r = this._base;
        Severity: Minor
        Found in src/Integer.js - About 1 hr to fix

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

              cmp(other) {
                  // TODO optimize with _trim_positive
          
                  if (this.iszero()) {
                      if (other.iszero()) return 0;
          Severity: Minor
          Found in src/Integer.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

          Avoid too many return statements within this function.
          Open

                  return this._is_negative === 0
                      ? cmp(a, 0, a.length, b, 0, b.length)
                      : cmp(b, 0, b.length, a, 0, a.length);
          Severity: Major
          Found in src/Integer.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    if (this._is_negative > other._is_negative) return 1;
            Severity: Major
            Found in src/Integer.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return new Integer(r, this._is_negative, c);
              Severity: Major
              Found in src/Integer.js - About 30 mins to fix

                Function sub has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    sub(other) {
                        if (this._is_negative !== other._is_negative) {
                            return other._is_negative
                                ? this.add(other.opposite())
                                : this.opposite().add(other).opposite();
                Severity: Minor
                Found in src/Integer.js - About 25 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