Gielert/NoodleJS

View on GitHub

Showing 40 of 40 total issues

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

class ChannelState extends AbstractHandler {
    handle(data) {
        let channel = this.client.channels.get(data.channelId)

        if(channel) {
Severity: Major
Found in src/handlers/ChannelState.js and 1 other location - About 7 hrs to fix
src/handlers/UserState.js on lines 5..19

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

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

class UserState extends AbstractHandler {
    handle(data) {
        let user = this.client.users.get(data.session)

        if (user) {
Severity: Major
Found in src/handlers/UserState.js and 1 other location - About 7 hrs to fix
src/handlers/ChannelState.js on lines 5..20

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

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

    stopListeningToChannel(id) {
        if (this.channels.has(id)) {
            return this.connection.writeProto('UserState', {session: this.user.session, listeningChannelRemove: [id]})
        } else {
            return Promise.reject('ChannelId unknown')
Severity: Major
Found in src/Client.js and 1 other location - About 2 hrs to fix
src/Client.js on lines 142..148

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

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

    startListeningToChannel(id) {
        if (this.channels.has(id)) {
            return this.connection.writeProto('UserState', {session: this.user.session, listeningChannelAdd: [id]})
        } else {
            return Promise.reject('ChannelId unknown')
Severity: Major
Found in src/Client.js and 1 other location - About 2 hrs to fix
src/Client.js on lines 155..161

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

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 5 locations. Consider refactoring.
Open

        if (data.links != null)
            data.links.forEach(val => {
                const channel = this.client.channels.get(val)
                if (channel)
                    this.links.set(channel.id, channel)
Severity: Major
Found in src/structures/Channel.js and 4 other locations - About 2 hrs to fix
src/structures/Channel.js on lines 55..60
src/structures/TextMessage.js on lines 20..25
src/structures/TextMessage.js on lines 27..32
src/structures/TextMessage.js on lines 34..39

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

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 5 locations. Consider refactoring.
Open

        if (data.treeId != null)
            data.treeId.forEach(id => {
                const channel = this.client.channels.get(id)
                if (channel)
                    this.trees.set(channel.id, channel)
Severity: Major
Found in src/structures/TextMessage.js and 4 other locations - About 2 hrs to fix
src/structures/Channel.js on lines 45..50
src/structures/Channel.js on lines 55..60
src/structures/TextMessage.js on lines 20..25
src/structures/TextMessage.js on lines 27..32

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

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 5 locations. Consider refactoring.
Open

        if (data.linksAdd != null)
            data.linksAdd.forEach(val => {
                const channel = this.client.channels.get(val)
                if (channel)
                    this.links.set(channel.id, channel)
Severity: Major
Found in src/structures/Channel.js and 4 other locations - About 2 hrs to fix
src/structures/Channel.js on lines 45..50
src/structures/TextMessage.js on lines 20..25
src/structures/TextMessage.js on lines 27..32
src/structures/TextMessage.js on lines 34..39

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

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 5 locations. Consider refactoring.
Open

        if (data.channelId != null)
            data.channelId.forEach(id => {
                const channel = this.client.channels.get(id)
                if (channel)
                    this.channels.set(channel.id, channel)
Severity: Major
Found in src/structures/TextMessage.js and 4 other locations - About 2 hrs to fix
src/structures/Channel.js on lines 45..50
src/structures/Channel.js on lines 55..60
src/structures/TextMessage.js on lines 20..25
src/structures/TextMessage.js on lines 34..39

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

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 5 locations. Consider refactoring.
Open

        if (data.session != null)
            data.session.forEach(session => {
                const user = this.client.users.get(session)
                if (user)
                    this.users.set(user.session, user)
Severity: Major
Found in src/structures/TextMessage.js and 4 other locations - About 2 hrs to fix
src/structures/Channel.js on lines 45..50
src/structures/Channel.js on lines 55..60
src/structures/TextMessage.js on lines 27..32
src/structures/TextMessage.js on lines 34..39

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

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

        if (this.channels.size) {
            packet.channelId = []
            for (const channel of this.channels.array()) {
                packet.channelId.push(Number(channel.id))
            }
Severity: Major
Found in src/structures/TextMessage.js and 2 other locations - About 1 hr to fix
src/structures/TextMessage.js on lines 55..60
src/structures/TextMessage.js on lines 68..73

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

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

        if (this.users.size) {
            packet.session = []
            for (const user of this.users.array()) {
                packet.session.push(Number(user.session))
            }
Severity: Major
Found in src/structures/TextMessage.js and 2 other locations - About 1 hr to fix
src/structures/TextMessage.js on lines 61..66
src/structures/TextMessage.js on lines 68..73

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

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

        if (this.trees.size) {
            packet.treeId = []
            for (const channel of this.trees.array()) {
                packet.treeId.push(Number(channel.id))
            }
Severity: Major
Found in src/structures/TextMessage.js and 2 other locations - About 1 hr to fix
src/structures/TextMessage.js on lines 55..60
src/structures/TextMessage.js on lines 61..66

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

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

    setup(data) {

        if (data.channelId == null)
            return

Severity: Minor
Found in src/structures/Channel.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 find has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  find(propOrFn, value) {
    if (typeof propOrFn === 'string') {
      if (typeof value === 'undefined') throw new Error('Value must be specified.');
      for (const item of this.values()) {
        if (item[propOrFn] === value) return item;
Severity: Minor
Found in src/structures/Collection.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 setup has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    setup(data) {

        if (data.channelId == null)
            return

Severity: Minor
Found in src/structures/Channel.js - About 1 hr to fix

    Function readAudio has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        readAudio(data) {
            // Packet format:
            // https://github.com/mumble-voip/mumble-protocol/blob/master/voice_data.rst#packet-format
            const audioType = (data[0] & 0xE0) >> 5;
            const audioTarget = data[0] & 0x1F;
    Severity: Minor
    Found in src/Connection.js - About 1 hr to fix

      Function fromVarInt has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static fromVarInt(buf) {
              // TODO: 111110__ + varint    Negative recursive varint
              // TODO: 111111xx           Byte-inverted negative two bit number (~xx)
      
              var retVal = {
      Severity: Minor
      Found in src/Util.js - About 1 hr to fix

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

            constructor(options = {}) {
                super()
        
                /**
                 * The options the client is instantiated with
        Severity: Minor
        Found in src/Client.js - About 1 hr to fix

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

              _processAudioBuffer() {
                  if(!this.lastWrite ||
                     this.lastWrite + 20 * Constants.Audio.frameLength < Date.now()) {
                     this.voiceSequence = this.connection.voiceSequence
                     this.lastWrite = Date.now()
          Severity: Minor
          Found in src/voice/DispatchStream.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 _processAudioBuffer has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              _processAudioBuffer() {
                  if(!this.lastWrite ||
                     this.lastWrite + 20 * Constants.Audio.frameLength < Date.now()) {
                     this.voiceSequence = this.connection.voiceSequence
                     this.lastWrite = Date.now()
          Severity: Minor
          Found in src/voice/DispatchStream.js - About 1 hr to fix
            Severity
            Category
            Status
            Source
            Language