| Conditions | 1 |
| Paths | 72 |
| Total Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 | /** |
||
| 23 | (function () { |
||
| 24 | 'use strict'; |
||
| 25 | /** |
||
| 26 | * @ngdoc directive |
||
| 27 | * @name passmanApp.directive:passwordGen |
||
| 28 | * @description |
||
| 29 | * # passwordGen |
||
| 30 | */ |
||
| 31 | angular.module('passmanApp') |
||
| 32 | .directive('credentialCounter', [function () { |
||
| 33 | return { |
||
| 34 | template: '<div ng-show="counter" translate="number.filtered" translate-values="{number_filtered: counter, credential_number: total}"></div>', |
||
| 35 | replace: false, |
||
| 36 | restrict: 'A', |
||
| 37 | scope: { |
||
| 38 | filteredCredentials: '=credentialCounter', |
||
| 39 | deleteTime: '=', |
||
| 40 | vault: '=', |
||
| 41 | filters: '=' |
||
| 42 | }, |
||
| 43 | |||
| 44 | link: function (scope) { |
||
| 45 | function countCredentials() { |
||
| 46 | var countedCredentials = 0; |
||
| 47 | var total = 0; |
||
| 48 | if(!scope.vault || !scope.vault.hasOwnProperty('credentials')){ |
||
| 49 | return; |
||
| 50 | } |
||
| 51 | |||
| 52 | angular.forEach(scope.vault.credentials, function (credential) { |
||
| 53 | var pos = scope.filteredCredentials.map(function(c) { return c.guid; }).indexOf(credential.guid); |
||
| 54 | |||
| 55 | if (scope.deleteTime === 0 && credential.hidden === 0 && credential.delete_time === 0) { |
||
| 56 | total = total + 1; |
||
| 57 | countedCredentials = (pos !== -1) ? countedCredentials + 1 : countedCredentials; |
||
| 58 | } |
||
| 59 | |||
| 60 | if (scope.deleteTime > 0 && credential.hidden === 0 && credential.delete_time > 0) { |
||
| 61 | total = total + 1; |
||
| 62 | countedCredentials = (pos !== -1) ? countedCredentials + 1 : countedCredentials; |
||
| 63 | } |
||
| 64 | |||
| 65 | }); |
||
| 66 | scope.counter = countedCredentials; |
||
| 67 | scope.total = total; |
||
| 68 | } |
||
| 69 | scope.$watch('[filteredCredentials, deleteTime, filters]', function () { |
||
| 70 | countCredentials(); |
||
| 71 | }, true); |
||
| 72 | } |
||
| 73 | }; |
||
| 74 | }]); |
||
| 75 | }()); |