Showing 73 of 75 total issues
Function constructor
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Confirmed
constructor(options: WebGroupOptions = {}) {
const wc = new WebChannel(options)
wcs.set(this, wc)
/**
- Read upRead up
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 initHandlers
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
private initHandlers() {
// Configure handlers
this.wsOrDc.onmessage = ({ data }: { data: ArrayBuffer }) => {
try {
const msg = Message.decode(new Uint8Array(data))
- Read upRead up
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
WebChannel
has 27 functions (exceeds 20 allowed). Consider refactoring. Confirmed
export class WebChannel implements IStream<OutWcMessage, InWcMsg> {
public readonly STREAM_ID = 2
public members: number[]
public topologyEnum: TopologyEnum
public myId: number
Function constructor
has 73 lines of code (exceeds 25 allowed). Consider refactoring. Open
constructor(wc: WebChannel) {
super(wc, FullMesh.SERVICE_ID, proto.Message)
this.adjacentMembers = new Map()
this.distantMembers = new Map()
this.antecedentId = 0
Function findRoutedChannel
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
private findRoutedChannel(
distantMember: IDistantMember | undefined,
distance: number
): Channel | undefined {
if (distantMember) {
- Read upRead up
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 updateAntecedentId
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
private updateAntecedentId() {
if (this.adjacentMembers.size > 0) {
let maxId = -1
let desiredId = -1
for (const id of this.wc.members) {
- Read upRead up
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 constructor
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Confirmed
constructor(options: BotOptions) {
botServer = new BotServer(options)
/**
* Read-only NodeJS http server instance.
Function reconnectToSignaling
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
private reconnectToSignaling() {
if (this.members.length === 1 && (!isVisible() || !isOnline())) {
this.internalLeave()
} else {
log.webgroup(`reconnect to Signaling server in ${REJOIN_TIMEOUT}ms`)
- Read upRead up
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 handleMessage
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Confirmed
handleMessage(msg: proto.Message) {
if (msg.type) {
switch (msg.type) {
case 'offer':
log.webrtc('REMOTE OFFER', { offer: msg.offer })
Function connectToMembers
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
private connectToMembers(ids: number[], adjacentId: number): Promise<void | void[]> {
const missingIds = ids.filter((id) => !this.adjacentMembers.has(id) && id !== this.wc.myId)
if (missingIds.length !== 0) {
log.topology(`TRY TO CONNECT to members`, missingIds)
const attempts: Array<Promise<void>> = []
Function setTopology
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
private setTopology(topologyEnum: TopologyEnum): void {
this.topologyEnum = topologyEnum
this.topology = new FullMesh(this)
this.topology.onState.subscribe((state: TopologyState) => {
log.webgroup('Topology state: ', TopologyState[state])
Function decodeUserMessage
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
decodeUserMessage(bytes: Uint8Array, senderId: number): UserDataType | undefined {
try {
const { length, type, contentType, full, chunk } = super.decode(bytes) as {
length: number
type: proto.Message.Type
Function constructor
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
constructor(
wc: WebChannel,
wsOrDc: WebSocket | RTCDataChannel,
type: number,
id: number,
Similar blocks of code found in 2 locations. Consider refactoring. Open
connection.reject = (err) => {
// This is necessary for some scenarios in order to rid of UnhandledPromiseRejectionWarning errors in NodeJS and similar errors/warnings in browsers
connection.promise.catch(() => {})
clearTimeout(connectionTimer)
this.connections.delete(id)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
connection.reject = (err) => {
// This is necessary for some scenarios in order to rid of UnhandledPromiseRejectionWarning errors in NodeJS and similar errors/warnings in browsers
connection.promise.catch(() => {})
clearTimeout(responseTimer)
this.connections.delete(id)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Function constructor
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
constructor(
id: number,
pc: RTCPeerConnection,
send: (msg: proto.IMessage) => void,
remotes: Map<number, Remote>,
Function initHandlers
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
private initHandlers() {
// Configure handlers
this.wsOrDc.onmessage = ({ data }: { data: ArrayBuffer }) => {
try {
const msg = Message.decode(new Uint8Array(data))
Function init
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Confirmed
private init(): void {
this.webSocketServer = new Server({
perMessageDeflate: this.perMessageDeflate,
verifyClient: (info: any) => this.validateURLQuery(info),
server: this.server,
Function create
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
create(
id: number,
connectionTimeout: number,
responseTimeout: number,
onConnectionTimeoutCallback: () => void
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (!theOther.dcTried) {
log.channelBuilder(`Prompt the other to connect over RTCDataChannel`)
this.allStreams.sendOver(
streamId,
{ negotiation: { initiator, passive } },
- Read upRead up
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 64.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76