| Conditions | 1 |
| Paths | 6 |
| Total Lines | 89 |
| Lines | 0 |
| Ratio | 0 % |
| 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 | /** |
||
| 23 | (function () { |
||
| 24 | 'use strict'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @ngdoc function |
||
| 28 | * @name passmanApp.controller:MainCtrl |
||
| 29 | * @description |
||
| 30 | * # MainCtrl |
||
| 31 | * Controller of the passmanApp |
||
| 32 | */ |
||
| 33 | angular.module('passmanApp') |
||
| 34 | .controller('MainCtrl', ['$scope', '$rootScope', '$location', 'SettingsService', '$window', '$interval', '$filter', function ($scope, $rootScope, $location, SettingsService, $window, $interval, $filter) { |
||
| 35 | $scope.selectedVault = false; |
||
| 36 | |||
| 37 | $scope.http_warning_hidden = true; |
||
| 38 | if ($location.$$protocol === 'http' && $location.$$host !== 'localhost' && $location.$host !== '127.0.0.1') { |
||
| 39 | $scope.using_http = true; |
||
| 40 | $scope.http_warning_hidden = false; |
||
| 41 | |||
| 42 | } |
||
| 43 | |||
| 44 | $rootScope.$on('settings_loaded', function(){ |
||
| 45 | if (SettingsService.isEnabled('disable_contextmenu')) { |
||
| 46 | document.addEventListener('contextmenu', function (event) { |
||
| 47 | event.preventDefault(); |
||
| 48 | }); |
||
| 49 | } |
||
| 50 | if (SettingsService.isEnabled('https_check')) { |
||
| 51 | $scope.http_warning_hidden = true; |
||
| 52 | } |
||
| 53 | |||
| 54 | if(SettingsService.isEnabled('disable_debugger')){ |
||
| 55 | (function a() { |
||
| 56 | try { |
||
| 57 | (function b(i) { |
||
| 58 | if (('' + (i / i)).length !== 1 || i % 20 === 0) { |
||
| 59 | (function() {}).constructor('debugger')(); |
||
| 60 | } else { |
||
| 61 | // This debugger statement is allowed to block javascript console |
||
| 62 | /*jshint -W087 */ |
||
| 63 | debugger; |
||
| 64 | } |
||
| 65 | b(++i); |
||
| 66 | })(0); |
||
| 67 | } catch (e) { |
||
| 68 | setTimeout(a, 5000); |
||
| 69 | } |
||
| 70 | })(); |
||
| 71 | } |
||
| 72 | }); |
||
| 73 | |||
| 74 | $rootScope.setHttpWarning = function (state) { |
||
| 75 | $scope.http_warning_hidden = state; |
||
| 76 | }; |
||
| 77 | |||
| 78 | $rootScope.$on('app_menu', function (evt, shown) { |
||
| 79 | $scope.app_sidebar = shown; |
||
| 80 | }); |
||
| 81 | |||
| 82 | $rootScope.$on('logout', function () { |
||
| 83 | $scope.selectedVault = false; |
||
| 84 | }); |
||
| 85 | |||
| 86 | var tickSessionTimer = function(){ |
||
| 87 | if($scope.session_time_left){ |
||
| 88 | $scope.session_time_left--; |
||
| 89 | var session_time_left_formatted = $filter('toHHMMSS')($scope.session_time_left); |
||
| 90 | $scope.translationData = { |
||
| 91 | session_time: session_time_left_formatted |
||
| 92 | }; |
||
| 93 | $rootScope.$broadcast('logout_timer_tick_tack', $scope.session_time_left); |
||
| 94 | if($scope.session_time_left === 0){ |
||
| 95 | $window.location.reload(); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | }; |
||
| 99 | |||
| 100 | $scope.session_time_left = false; |
||
| 101 | $scope.$on('logout_timer_set', function(evt, timer){ |
||
| 102 | $scope.session_time_left = timer; |
||
| 103 | $scope.translationData = { |
||
| 104 | session_time: timer |
||
| 105 | }; |
||
| 106 | $interval(tickSessionTimer, 1000); |
||
| 107 | }); |
||
| 108 | |||
| 109 | }]); |
||
| 110 | |||
| 111 | }()); |