Conditions | 1 |
Paths | 4 |
Total Lines | 135 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 | /* global API */ |
||
36 | .controller('EditCtrl', ['$scope', '$routeParams', '$mdToast','$timeout', function ($scope, $routeParams, $mdToast, $timeout) { |
||
37 | API.runtime.sendMessage(API.runtime.id, { |
||
38 | method: "getCredentialByGuid", |
||
39 | args: $routeParams.guid |
||
40 | }).then(function (credential) { |
||
41 | $scope.credential = credential; |
||
42 | $scope.credential.password_repeat = angular.copy(credential.password); |
||
43 | $scope.$apply(); |
||
44 | }); |
||
45 | |||
46 | var storage = new API.Storage(); |
||
47 | |||
48 | function genPwd(settings) { |
||
49 | /* jshint ignore:start */ |
||
50 | var password = generatePassword(settings['length'], |
||
51 | settings.useUppercase, |
||
52 | settings.useLowercase, |
||
53 | settings.useDigits, |
||
54 | settings.useSpecialChars, |
||
55 | settings.minimumDigitCount, |
||
56 | settings.avoidAmbiguousCharacters, |
||
57 | settings.requireEveryCharType); |
||
58 | /* jshint ignore:end */ |
||
59 | return password; |
||
60 | } |
||
61 | |||
62 | $scope.pw_settings = null; |
||
63 | function getPasswordGenerationSettings(cb) { |
||
|
|||
64 | var default_settings = { |
||
65 | 'length': 12, |
||
66 | 'useUppercase': true, |
||
67 | 'useLowercase': true, |
||
68 | 'useDigits': true, |
||
69 | 'useSpecialChars': true, |
||
70 | 'minimumDigitCount': 3, |
||
71 | 'avoidAmbiguousCharacters': false, |
||
72 | 'requireEveryCharType': true |
||
73 | }; |
||
74 | storage.get('password_generator_settings').then(function (_settings) { |
||
75 | if (!_settings) { |
||
76 | _settings = default_settings; |
||
77 | } |
||
78 | |||
79 | $scope.pw_settings = _settings; |
||
80 | }).error(function () { |
||
81 | $scope.pw_settings = default_settings; |
||
82 | }); |
||
83 | } |
||
84 | |||
85 | getPasswordGenerationSettings(); |
||
86 | |||
87 | var custom_field = { |
||
88 | label: '', |
||
89 | value: '', |
||
90 | field_type: 'text', |
||
91 | secret: false |
||
92 | }; |
||
93 | |||
94 | $scope.new_custom_field = angular.copy(custom_field); |
||
95 | |||
96 | $scope.addCustomField = function (_field) { |
||
97 | var field = angular.copy(_field); |
||
98 | if (!field.label || !field.value) { |
||
99 | return; |
||
100 | } |
||
101 | $scope.credential.custom_fields.push(field); |
||
102 | $scope.new_custom_field = angular.copy(custom_field); |
||
103 | }; |
||
104 | |||
105 | $scope.deleteCustomField = function (field) { |
||
106 | var idx = $scope.credential.custom_fields.indexOf(field); |
||
107 | $scope.credential.custom_fields.splice(idx, 1); |
||
108 | }; |
||
109 | |||
110 | $scope.pwFieldShown = false; |
||
111 | |||
112 | $scope.togglePwField = function () { |
||
113 | $scope.pwFieldShown = !$scope.pwFieldShown; |
||
114 | }; |
||
115 | |||
116 | |||
117 | function generate_pass(inputId) { |
||
118 | |||
119 | } |
||
120 | var round = 0; |
||
121 | $scope.generatePassword = function () { |
||
122 | var new_password = genPwd($scope.pw_settings); |
||
123 | $scope.credential.password = new_password; |
||
124 | $scope.credential.password_repeat = new_password; |
||
125 | $timeout(function () { |
||
126 | if (round < 10) { |
||
127 | $scope.generatePassword(); |
||
128 | round++; |
||
129 | } else { |
||
130 | round = 0; |
||
131 | } |
||
132 | }, 10); |
||
133 | }; |
||
134 | |||
135 | $scope.saveCredential = function () { |
||
136 | if (!$scope.credential.label) { |
||
137 | $mdToast.showSimple(API.i18n.getMessage('label_required')); |
||
138 | return; |
||
139 | } |
||
140 | |||
141 | if ($scope.credential.password !== $scope.credential.password_repeat) { |
||
142 | $mdToast.showSimple(API.i18n.getMessage('no_password_match')); |
||
143 | return; |
||
144 | } |
||
145 | |||
146 | if ($scope.new_custom_field.label && $scope.new_custom_field.value) { |
||
147 | $scope.credential.custom_fields.push(angular.copy($scope.new_custom_field)); |
||
148 | } |
||
149 | delete $scope.credential.password_repeat; |
||
150 | |||
151 | API.runtime.sendMessage(API.runtime.id, { |
||
152 | method: "saveCredential", |
||
153 | args: $scope.credential |
||
154 | }).then(function (credential) { |
||
155 | if (!$scope.credential.credential_id) { |
||
156 | $mdToast.showSimple(API.i18n.getMessage('credential_created')); |
||
157 | } else { |
||
158 | $mdToast.showSimple(API.i18n.getMessage('credential_updated')); |
||
159 | } |
||
160 | window.location = '#!/'; |
||
161 | }); |
||
162 | |||
163 | }; |
||
164 | |||
165 | $scope.cancel = function () { |
||
166 | window.location = '#!/'; |
||
167 | }; |
||
168 | |||
169 | |||
170 | }]); |
||
171 | }()); |
||
173 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.