| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 77 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 2 | ||
| Bugs | 0 | Features | 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 | /**  | 
            ||
| 26 | 	    getCredentialsWithFiles: function(credentials, FileService, EncryptService) { | 
            ||
| 27 | 		var t = { | 
            ||
| 28 | cred: credentials,  | 
            ||
| 29 | FS: FileService,  | 
            ||
| 30 | ES: EncryptService  | 
            ||
| 31 | };  | 
            ||
| 32 | /** global: C_Promise */  | 
            ||
| 33 | 		return new C_Promise(function() { | 
            ||
| 34 | var _this = this.parent;  | 
            ||
| 35 | var credentials = _this.cred;  | 
            ||
| 36 | this.parent.total = 0;  | 
            ||
| 37 | this.parent.finished = 0;  | 
            ||
| 38 | this.parent.fileGUID_cred = [];  | 
            ||
| 39 | this.parent.files = [];  | 
            ||
| 40 | 		    this.parent.step = (function(file) { | 
            ||
| 41 | this.parent.finished ++;  | 
            ||
| 42 | 			this.call_progress({ | 
            ||
| 43 | total: this.parent.total,  | 
            ||
| 44 | finished: this.parent.finished  | 
            ||
| 45 | });  | 
            ||
| 46 | |||
| 47 | var dta = this.parent.fileGUID_cred[file.guid];  | 
            ||
| 48 | |||
| 49 | file.filename = this.parent.ES.decryptString(file.filename, this.parent.cred[dta.cred_pos].vault_key);  | 
            ||
| 50 | file.file_data = this.parent.ES.decryptString(file.file_data, this.parent.cred[dta.cred_pos].vault_key);  | 
            ||
| 51 | |||
| 52 | // Files and custom_fields have different field structure  | 
            ||
| 53 | 			if (dta.on === 'files') { | 
            ||
| 54 | this.parent.cred[dta.cred_pos][dta.on][dta.at] = file;  | 
            ||
| 55 | }  | 
            ||
| 56 | 			else { | 
            ||
| 57 | this.parent.cred[dta.cred_pos][dta.on][dta.at].value = file;  | 
            ||
| 58 | }  | 
            ||
| 59 | |||
| 60 | // We have finished downloading everything, so let's hand over job to somewhere else!  | 
            ||
| 61 | 			if (this.parent.total === this.parent.finished) { | 
            ||
| 62 | this.call_then(this.parent.cred);  | 
            ||
| 63 | }  | 
            ||
| 64 | }).bind(this);  | 
            ||
| 65 | |||
| 66 | 		    for (var i = 0; i < credentials.length; i++) { | 
            ||
| 67 | |||
| 68 | var item = credentials[i];  | 
            ||
| 69 | |||
| 70 | // Custom fields  | 
            ||
| 71 | 			for (c = 0; c < item.custom_fields.length; c++) { | 
            ||
| 72 | var cf = item.custom_fields[c];  | 
            ||
| 73 | 			    if (cf.field_type === 'file') { | 
            ||
| 74 | this.parent.total ++;  | 
            ||
| 75 | 				this.parent.fileGUID_cred[cf.value.guid] = { | 
            ||
| 76 | cred_pos: i,  | 
            ||
| 77 | on: 'custom_fields',  | 
            ||
| 78 | at: c  | 
            ||
| 79 | };  | 
            ||
| 80 | |||
| 81 | 				this.parent.FS.getFile(cf.value).then((function(data){ | 
            ||
| 82 | this.parent.step(data);  | 
            ||
| 83 | }).bind(this));  | 
            ||
| 84 | }  | 
            ||
| 85 | }  | 
            ||
| 86 | |||
| 87 | // Also get all files  | 
            ||
| 88 | 			for (var c = 0; c < item.files.length; c++) { | 
            ||
| 89 | this.parent.total ++;  | 
            ||
| 90 | 			    this.parent.fileGUID_cred[item.files[c].guid] = { | 
            ||
| 91 | cred_pos: i,  | 
            ||
| 92 | on: 'files',  | 
            ||
| 93 | at: c  | 
            ||
| 94 | };  | 
            ||
| 95 | |||
| 96 | 			    this.parent.FS.getFile(item.files[c]).then((function(data){ | 
            ||
| 97 | this.parent.step(data);  | 
            ||
| 98 | }).bind(this));  | 
            ||
| 99 | }  | 
            ||
| 100 | }  | 
            ||
| 101 | }, t);  | 
            ||
| 102 | }  | 
            ||
| 103 | };  | 
            ||
| 105 | 
You can rewrite this statement in dot notation: