File WebSocket.js
has 577 lines of code (exceeds 250 allowed). Consider refactoring. Open
'use strict';
//
// wsd
// Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
// MIT Licensed
Function initAsClient
has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring. Open
function initAsClient(self, address, protocols, opts) {
var options = {
protocolVersion: protocolVersion,
perMessageDeflate: true
};
- 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 initAsClient
has 163 lines of code (exceeds 25 allowed). Consider refactoring. Open
function initAsClient(self, address, protocols, opts) {
var options = {
protocolVersion: protocolVersion,
perMessageDeflate: true
};
Function establishConnection
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
function establishConnection(self, ReceiverClass, SenderClass, socket, u) {
var upgradeHead = u;
var called = false;
socket.setTimeout(0);
Function send
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
WebSocket.prototype.send = function send(data, options, cb) {
var self = this;
if(typeof options === 'function') {
cb = options;
options = {};
Consider simplifying this complex logical expression. Open
if(!options.binary) {
options.binary = (
data instanceof ArrayBuffer ||
data instanceof Buffer ||
data instanceof Uint8Array ||
Function upgrade
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
req.once('upgrade', function upgrade(res, socket, upgradeHead) {
if(self.readyState === WebSocket.CLOSED) {
self.emit('close');
self.removeAllListeners();
return socket.end();
Function sendStream
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
function sendStream(instance, stream, options, cb) {
stream.on('data', function incoming(data) {
if(instance.readyState !== WebSocket.OPEN) {
if(typeof cb === 'function') {
cb(new Error('not opened'));
- 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 stream
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
WebSocket.prototype.stream = function stream(options, cb) {
if(typeof options === 'function') {
cb = options;
options = {};
}
- 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 send
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
WebSocket.prototype.send = function send(data, options, cb) {
var self = this;
if(typeof options === 'function') {
cb = options;
options = {};
- 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 stream
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
WebSocket.prototype.stream = function stream(options, cb) {
if(typeof options === 'function') {
cb = options;
options = {};
}
Function cleanupWebsocketResources
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
function cleanupWebsocketResources(self, error) {
if(self.readyState === WebSocket.CLOSED) {
return;
}
Function cleanupWebsocketResources
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
function cleanupWebsocketResources(self, error) {
if(self.readyState === WebSocket.CLOSED) {
return;
}
- 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 close
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
WebSocket.prototype.close = function(code, data) {
switch(this.readyState) {
case WebSocket.CLOSED:
return;
case WebSocket.CONNECTING:
Function establishConnection
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function establishConnection(self, ReceiverClass, SenderClass, socket, u) {
var upgradeHead = u;
var called = false;
socket.setTimeout(0);
- 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 sendStream
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
function sendStream(instance, stream, options, cb) {
stream.on('data', function incoming(data) {
if(instance.readyState !== WebSocket.OPEN) {
if(typeof cb === 'function') {
cb(new Error('not opened'));
Function initAsServerClient
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function initAsServerClient(self, req, socket, upgradeHead, opts) {
Function establishConnection
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function establishConnection(self, ReceiverClass, SenderClass, socket, u) {
Function WebSocket
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function WebSocket(address, protocols, options) {
if('string' === typeof protocols) {
protocols = [protocols];
} else if(!Array.isArray(protocols)) {
if(typeof protocols === 'object') {
- 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 buildHostHeader
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function buildHostHeader(isSecure, hostname, port) {
var headerHost = hostname;
if(hostname) {
if((isSecure && port !== 443) || (!isSecure && port !== 80)) {
headerHost = headerHost + ':' + port;
- 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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if(instance.readyState !== WebSocket.OPEN) {
if(typeof cb === 'function') {
cb(new Error('not opened'));
} else {
delete instance.queue;
- 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 73.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if(instance.readyState !== WebSocket.OPEN) {
if(typeof cb === 'function') {
cb(new Error('not opened'));
} else {
delete instance.queue;
- 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 73.
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
Object.defineProperty(WebSocket.prototype, 'bufferedAmount', {
get: function get() {
return !this.socket ? 0 : this.socket.bufferSize;
}
});
- 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 53.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if(opts) {
Object.keys(opts).forEach(function(k) {
options[k] = opts[k];
});
}
- 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 47.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if(opts) {
Object.keys(opts).forEach(function(k) {
options[k] = opts[k];
});
}
- 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 47.
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