| Conditions | 1 |
| Paths | 1 |
| Total Lines | 73 |
| 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 */ |
||
| 25 | (function () { |
||
| 26 | 'use strict'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @ngdoc function |
||
| 30 | * @name passmanApp.controller:MainCtrl |
||
| 31 | * @description |
||
| 32 | * # MainCtrl |
||
| 33 | * Controller of the passmanApp |
||
| 34 | */ |
||
| 35 | angular.module('passmanExtension') |
||
| 36 | .controller('ListCtrl', ['$scope', 'Settings', '$location', '$rootScope', function ($scope, Settings, $window, $rootScope) { |
||
| 37 | $scope.app = 'passman'; |
||
| 38 | var port = API.runtime.connect(null, { |
||
| 39 | name: "PassmanCommunication" |
||
| 40 | }); |
||
| 41 | |||
| 42 | var messageParser = function (message) { |
||
| 43 | var e = message.split(':'); |
||
| 44 | |||
| 45 | switch (e[0]) { |
||
| 46 | case "credential_amount": |
||
| 47 | $scope.credential_amount = e[1]; |
||
| 48 | $scope.refreshing_credentials = false; |
||
| 49 | } |
||
| 50 | |||
| 51 | $scope.$apply(); |
||
| 52 | }; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Connect to the background service |
||
| 56 | */ |
||
| 57 | var initApp = function () { |
||
| 58 | port.onMessage.addListener(messageParser); |
||
| 59 | API.runtime.sendMessage(API.runtime.id, {method: "getMasterPasswordSet"}).then(function (isPasswordSet) { |
||
| 60 | getActiveTab(); |
||
| 61 | $scope.refreshing_credentials = true; |
||
| 62 | setTimeout(function () { |
||
| 63 | port.postMessage("credential_amount"); |
||
| 64 | }, 500); |
||
| 65 | }); |
||
| 66 | }; |
||
| 67 | |||
| 68 | $scope.refreshing_credentials = false; |
||
| 69 | $scope.refresh = function () { |
||
| 70 | $scope.refreshing_credentials = true; |
||
| 71 | API.runtime.sendMessage(API.runtime.id, {method: "getCredentials"}).then(function () { |
||
| 72 | setTimeout(function () { |
||
| 73 | port.postMessage("credential_amount"); |
||
| 74 | }, 2000); |
||
| 75 | }); |
||
| 76 | }; |
||
| 77 | |||
| 78 | var getActiveTab = function (cb) { |
||
| 79 | API.tabs.query({currentWindow: true, active: true}).then(function (tab) { |
||
| 80 | API.runtime.sendMessage(API.runtime.id, { |
||
| 81 | method: "getCredentialsByUrl", |
||
| 82 | args: [tab[0].url] |
||
| 83 | }).then(function (_logins) { |
||
| 84 | //var url = backgroundPage.processURL(tab.url, $rootScope.app_settings.ignoreProtocol, $rootScope.app_settings.ignoreSubdomain, $rootScope.app_settings.ignorePath); |
||
| 85 | $scope.found_credentials = _logins; |
||
| 86 | $scope.$apply(); |
||
| 87 | }); |
||
| 88 | }); |
||
| 89 | }; |
||
| 90 | |||
| 91 | initApp(); |
||
| 92 | |||
| 93 | $scope.edit = function (credential) { |
||
| 94 | window.location = '#!/edit/' + credential.guid; |
||
| 95 | }; |
||
| 96 | }]); |
||
| 97 | }()); |
||
| 98 | |||
| 99 |
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.