| Conditions | 2 |
| Paths | 8 |
| Total Lines | 52 |
| Lines | 52 |
| Ratio | 100 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* TODO |
||
| 114 | View Code Duplication | app.get('/exams/', function (req, res, next) {
|
|
| 115 | if (program.fulllog) {
|
||
| 116 | var start = new Date(); |
||
| 117 | console.log((timeStamp() + 'Started to query the exams: ').cyan + req.query.id.yellow); |
||
|
1 ignored issue
–
show
|
|||
| 118 | } |
||
| 119 | access.login(req.query.id, req.query.pwd, res, function (headers, ires) {
|
||
| 120 | var ret = {};
|
||
| 121 | var $ = cheerio.load(ires.text); |
||
| 122 | ret.name = escaper.unescape($('.block1text').html()).match(/姓名:.+</)[0].replace('<', '').substring(3);
|
||
| 123 | ret.id = req.query.id; |
||
| 124 | |||
| 125 | superagent.post('http://csujwc.its.csu.edu.cn/jsxsd/xsks/xsksap_list')
|
||
| 126 | .set(headers) |
||
| 127 | .type('form')
|
||
| 128 | .send({
|
||
| 129 | xqlbmc: '', |
||
| 130 | xnxqid: '2016-2017-1', //TODO: 添加别的选项,或者通过参数传入 |
||
| 131 | xqlb: '' |
||
| 132 | }) |
||
| 133 | .end(function (err, iires) {
|
||
| 134 | if (err) {
|
||
| 135 | console.log((timeStamp() + 'Failed to reach exams page\n' + err.stack).red); |
||
|
1 ignored issue
–
show
|
|||
| 136 | res.send({ error: '获取成绩失败' });
|
||
| 137 | return next(err); |
||
| 138 | } |
||
| 139 | program.fulllog && console.log((timeStamp() + 'Successfully entered exams page.').green); |
||
| 140 | |||
| 141 | $ = cheerio.load(iires.text); |
||
| 142 | |||
| 143 | let exams = []; |
||
| 144 | |||
| 145 | $('#dataList tr').each(function (index) {
|
||
| 146 | if (index === 0) |
||
| 147 | return; |
||
| 148 | let item = $(this).find('td');
|
||
| 149 | let subject = {};
|
||
| 150 | subject.subject = escaper.unescape(item.eq(3).text()); |
||
| 151 | subject.time = escaper.unescape(item.eq(4).text()); |
||
| 152 | subject.location = escaper.unescape(item.eq(5).text()); |
||
| 153 | subject.seat = escaper.unescape(item.eq(6).text()); |
||
| 154 | exams.push(subject); |
||
| 155 | }); |
||
| 156 | |||
| 157 | ret.exams = exams; |
||
| 158 | |||
| 159 | access.logout(headers, res, function() {
|
||
| 160 | res.send(JSON.stringify(ret)); |
||
| 161 | program.fulllog && console.log((timeStamp() + 'Successfully logged out: ').green + req.query.id.yellow + (' (processed in ' + (new Date() - start) + 'ms)').green);
|
||
|
1 ignored issue
–
show
|
|||
| 162 | }); |
||
| 163 | }); |
||
| 164 | }); |
||
| 165 | }); |
||
| 166 | |||
| 168 | console.log((timeStamp() + 'The server is now running on port ' + port + '.').green); |