Complexity greater than authorized in AngularJS Controller (SonarLint issue)

前端 未结 2 483
时光取名叫无心
时光取名叫无心 2021-01-20 02:40

I use SonarLint with Eclipse, and I\'m codding an application using AngularJS. I had a problem with a controller so I was trying to clean it a bit

2条回答
  •  佛祖请我去吃肉
    2021-01-20 03:04

    Is there something wrong with it?

    You're looking for an objective answer to a subjective question. Let's say that the more complex a function gets, the more you (or someone else) will struggle to maintain it. This issue is telling you that you've reached an arbitrary point where the code may be getting hard to understand.

    it isn't complexity 11, is it?

    The way SonarQube counts complexity doesn't quite match any of the currently enunciated standards, but here's how it got the number 11:

    app.controller('LauncherCtrl', function ($scope, $http) {  // +1
    
        $scope.genStatus = "stopped";
    
        $scope.startgenerator = function() {                   // +1
            $http.get('/start').success(function () {          // +1
                $scope.updateStatus();
            });
        };
    
        $scope.resumegenerator = function() {                 // +1
            $http.get('/resume').success(function () {        // +1
                $scope.updateStatus();
            });
        };
    
        $scope.suspendgenerator = function() {                // +1
            $http.get('/suspend').success(function () {       // +1
                $scope.updateStatus();
            });
        };
    
        $scope.stopgenerator = function() {                   // +1
            $http.get('/stop').success(function () {          // +1
                $scope.updateStatus();
            });
        };
    
        $scope.updateStatus = function() {                    // +1
            $http.get('/status').success(function (response) {// +1
                  $scope.genStatus = response.data;
            });
        };
    
        $scope.updateStatus();
    });
    

提交回复
热议问题