File URI.js
has 1284 lines of code (exceeds 250 allowed). Consider refactoring. Open
/*!
* URI.js - Mutating URLs
*
* Version: 1.8.3
*
Function equals
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
p.equals = function(uri) {
var one = this.clone();
var two = new URI(uri);
var one_map = {};
var two_map = {};
Function is
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
p.is = function(what) {
var ip = false;
var ip4 = false;
var ip6 = false;
var name = false;
Function normalizePath
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
p.normalizePath = function(build) {
if (this._parts.urn) {
return this;
}
if (!this._parts.path || this._parts.path === '/') {
Function relativeTo
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
p.relativeTo = function(base) {
var relative = this.clone();
var properties = ['protocol', 'username', 'password', 'hostname', 'port'];
var common, _base, _this, _base_diff, _this_diff;
if (this._parts.urn) {
Function segment
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
p.segment = function(segment, v, build) {
var separator = this._parts.urn ? ':' : '/';
var path = this.path();
var absolute = path.substring(0, 1) === '/';
var segments = path.split(separator);
Function suffix
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
p.suffix = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined || v === true) {
Function tld
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
p.tld = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (typeof v === 'boolean') {
Function parse
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
URI.parse = function(string, parts) {
var pos, t;
if (!parts) {
parts = {};
}
Function directory
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
p.directory = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined || v === true) {
Function readable
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
p.readable = function() {
var uri = this.clone();
// removing username, password, because they shouldn't be displayed according to RFC 3986
uri.username("").password("").normalize();
var t = '';
Function domain
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
p.domain = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (typeof v === 'boolean') {
Function absoluteTo
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
p.absoluteTo = function(base) {
var resolved = this.clone();
var properties = ['protocol', 'username', 'password', 'hostname', 'port'];
var basedir, i, p;
if (this._parts.urn) {
Function filename
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
p.filename = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined || v === true) {
Avoid deeply nested control flow statements. Open
if (one_map[key][i] !== two_map[key][i]) {
return false;
}
Avoid deeply nested control flow statements. Open
if (data[key][i] !== undefined && unique[data[key][i] + ""] === undefined) {
t += "&" + URI.buildQueryParameter(key, data[key][i]);
if (duplicates !== true) {
unique[data[key][i] + ""] = true;
}
Avoid deeply nested control flow statements. Open
if (data[name] === value) {
data[name] = undefined;
} else if (isArray(data[name])) {
data[name] = filterArrayValues(data[name], value);
}
Consider simplifying this complex logical expression. Open
if (this._parts.hostname) {
relative = false;
ip4 = URI.ip4_expression.test(this._parts.hostname);
ip6 = URI.ip6_expression.test(this._parts.hostname);
ip = ip4 || ip6;
Avoid too many return
statements within this function. Open
return this;
Avoid too many return
statements within this function. Open
return this;
Avoid too many return
statements within this function. Open
return this;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return this;
Avoid too many return
statements within this function. Open
return this;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Identical blocks of code found in 2 locations. Consider refactoring. Open
(function(root, factory) {
// https://github.com/umdjs/umd/blob/master/returnExports.js
if (typeof exports === 'object') {
// Node
module.exports = factory(require('./punycode'), require('./IPv6'), require('./SecondLevelDomains'));
- 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 14082.
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