GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

third-party/angularjs/angular-1.6.5/docs/components/lunr-0.7.2/server.js   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 1.6

Size

Lines of Code 44
Function Count 5

Duplication

Duplicated Lines 44
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 31
dl 44
loc 44
rs 10
c 0
b 0
f 0
wmc 8
mnd 3
bc 3
fnc 5
bpm 0.6
cpm 1.6
noi 3

2 Functions

Rating   Name   Duplication   Size   Complexity  
A server.js ➔ error 4 4 1
A server.js ➔ notFound 4 4 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1 View Code Duplication
var http = require('http'),
2
    url = require('url'),
3
    join = require('path').join,
4
    extname = require('path').extname,
5
    join = require('path').join,
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable join already seems to be declared on line 3. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
6
    fs = require('fs'),
7
    port = process.argv[2] || 3000
8
9
var mime = {
10
    'html': 'text/html',
11
    'css': 'text/css',
12
    'js': 'application/javascript',
13
}
14
15
http.createServer(function(req, res){
16
  console.log('  \033[90m%s \033[36m%s\033[m', req.method, req.url)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
17
18
  var pathname = url.parse(req.url).pathname,
19
      path = join(process.cwd(), pathname)
20
21
  function notFound() {
22
    res.statusCode = 404
23
    res.end("404 Not Found\n")
24
  }
25
26
  function error(err) {
27
    res.statusCode = 500
28
    res.end(err.message + "\n")
29
  }
30
31
  fs.exists(path, function(exists){
32
    if (!exists) return notFound()
33
34
    fs.stat(path, function(err, stat){
35
      if (err) return error()
36
      if (stat.isDirectory()) path = join(path, 'index.html')
37
      res.setHeader('Cache-Control', 'no-cache')
38
      res.setHeader('Content-Type', mime[path.split('.').slice(-1)] || 'application/octet-stream')
39
      fs.createReadStream(path).pipe(res)
40
    })
41
  })
42
}).listen(port)
43
44
console.log('\n  Server listening on %d\n', port)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
45