aureooms/js-integer

View on GitHub

Showing 19 of 19 total issues

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 from has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            from(object, base = undefined, is_negative = 0) {
                if (object === null || object === undefined) return this.$0();
        
                switch (object.constructor.prototype) {
                    case Number.prototype:
        Severity: Minor
        Found in src/IntegerRing.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 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 from has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            from(object, base = undefined, is_negative = 0) {
                if (object === null || object === undefined) return this.$0();
        
                switch (object.constructor.prototype) {
                    case Number.prototype:
        Severity: Minor
        Found in src/IntegerRing.js - About 1 hr to fix

          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

            Identical blocks of code found in 4 locations. Consider refactoring.
            Open

            parser.addArgument(['-s'], {
                defaultValue: process.env.SEED || crypto.randomBytes(16).toString('hex'),
            });
            Severity: Major
            Found in _profile/mul.js and 3 other locations - About 40 mins to fix
            _profile/add.js on lines 13..15
            _profile/iadd.js on lines 13..15
            _profile/mod.js on lines 16..18

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

            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

            Identical blocks of code found in 4 locations. Consider refactoring.
            Open

            parser.addArgument(['-s'], {
                defaultValue: process.env.SEED || crypto.randomBytes(16).toString('hex'),
            });
            Severity: Major
            Found in _profile/add.js and 3 other locations - About 40 mins to fix
            _profile/iadd.js on lines 13..15
            _profile/mod.js on lines 16..18
            _profile/mul.js on lines 13..15

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

            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

            Identical blocks of code found in 4 locations. Consider refactoring.
            Open

            parser.addArgument(['-s'], {
                defaultValue: process.env.SEED || crypto.randomBytes(16).toString('hex'),
            });
            Severity: Major
            Found in _profile/iadd.js and 3 other locations - About 40 mins to fix
            _profile/add.js on lines 13..15
            _profile/mod.js on lines 16..18
            _profile/mul.js on lines 13..15

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

            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

            Identical blocks of code found in 4 locations. Consider refactoring.
            Open

            parser.addArgument(['-s'], {
                defaultValue: process.env.SEED || crypto.randomBytes(16).toString('hex'),
            });
            Severity: Major
            Found in _profile/mod.js and 3 other locations - About 40 mins to fix
            _profile/add.js on lines 13..15
            _profile/iadd.js on lines 13..15
            _profile/mul.js on lines 13..15

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

            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

            Function from_string has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                from_string(string, base = 10, is_negative = 0) {
                    if (string.length === 0)
                        throw new ValueError(
                            'IntegerRing#from_string cannot parse empty string.',
                        );
            Severity: Minor
            Found in src/IntegerRing.js - About 35 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

                    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

                Avoid too many return statements within this function.
                Open

                                return this.from_number(Number(object), is_negative);
                Severity: Major
                Found in src/IntegerRing.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return new Integer(
                                      object._base,
                                      object._is_negative ^ is_negative,
                                      object._limbs,
                                  );
                  Severity: Major
                  Found in src/IntegerRing.js - About 30 mins to fix

                    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

                      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

                      Severity
                      Category
                      Status
                      Source
                      Language