owncloud/core

View on GitHub
apps/provisioning_api/lib/Users.php

Summary

Maintainability
F
5 days
Test Coverage

File Users.php has 462 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
 * @author Joas Schilling <coding@schilljs.com>
 * @author Lukas Reschke <lukas@statuscode.ch>
Severity: Minor
Found in apps/provisioning_api/lib/Users.php - About 7 hrs to fix

    Function editUser has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

        public function editUser($parameters) {
            /** @var string $targetUserId */
            $targetUserId = $parameters['userid'];
    
            // Check if user is logged in
    Severity: Minor
    Found in apps/provisioning_api/lib/Users.php - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method editUser has 89 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function editUser($parameters) {
            /** @var string $targetUserId */
            $targetUserId = $parameters['userid'];
    
            // Check if user is logged in
    Severity: Major
    Found in apps/provisioning_api/lib/Users.php - About 3 hrs to fix

      Function addUser has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          public function addUser() {
              $userId = isset($_POST['userid']) ? $_POST['userid'] : null;
              $password = isset($_POST['password']) ? $_POST['password'] : null;
              $groups = isset($_POST['groups']) ? $_POST['groups'] : null;
              $user = $this->userSession->getUser();
      Severity: Minor
      Found in apps/provisioning_api/lib/Users.php - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function removeFromGroup has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public function removeFromGroup($parameters) {
              // Check if user is logged in
              $loggedInUser = $this->userSession->getUser();
              if ($loggedInUser === null) {
                  return new Result(null, API::RESPOND_UNAUTHORISED);
      Severity: Minor
      Found in apps/provisioning_api/lib/Users.php - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method addUser has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function addUser() {
              $userId = isset($_POST['userid']) ? $_POST['userid'] : null;
              $password = isset($_POST['password']) ? $_POST['password'] : null;
              $groups = isset($_POST['groups']) ? $_POST['groups'] : null;
              $user = $this->userSession->getUser();
      Severity: Minor
      Found in apps/provisioning_api/lib/Users.php - About 1 hr to fix

        Method removeFromGroup has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function removeFromGroup($parameters) {
                // Check if user is logged in
                $loggedInUser = $this->userSession->getUser();
                if ($loggedInUser === null) {
                    return new Result(null, API::RESPOND_UNAUTHORISED);
        Severity: Minor
        Found in apps/provisioning_api/lib/Users.php - About 1 hr to fix

          Function getUsersGroups has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getUsersGroups($parameters) {
                  // Check if user is logged in
                  $loggedInUser = $this->userSession->getUser();
                  if ($loggedInUser === null) {
                      return new Result(null, API::RESPOND_UNAUTHORISED);
          Severity: Minor
          Found in apps/provisioning_api/lib/Users.php - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method getUsers has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getUsers() {
                  $search = !empty($_GET['search']) ? $_GET['search'] : '';
                  $limit = !empty($_GET['limit']) ? $_GET['limit'] : null;
                  $offset = !empty($_GET['offset']) ? $_GET['offset'] : null;
          
          
          Severity: Minor
          Found in apps/provisioning_api/lib/Users.php - About 1 hr to fix

            Method getUser has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function getUser($parameters) {
                    $userId = $parameters['userid'];
            
                    // Check if user is logged in
                    $currentLoggedInUser = $this->userSession->getUser();
            Severity: Minor
            Found in apps/provisioning_api/lib/Users.php - About 1 hr to fix

              Method getUsersGroups has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function getUsersGroups($parameters) {
                      // Check if user is logged in
                      $loggedInUser = $this->userSession->getUser();
                      if ($loggedInUser === null) {
                          return new Result(null, API::RESPOND_UNAUTHORISED);
              Severity: Minor
              Found in apps/provisioning_api/lib/Users.php - About 1 hr to fix

                Function getUsers has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function getUsers() {
                        $search = !empty($_GET['search']) ? $_GET['search'] : '';
                        $limit = !empty($_GET['limit']) ? $_GET['limit'] : null;
                        $offset = !empty($_GET['offset']) ? $_GET['offset'] : null;
                
                
                Severity: Minor
                Found in apps/provisioning_api/lib/Users.php - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                        IUserManager $userManager,
                        IGroupManager $groupManager,
                        IUserSession $userSession,
                        ILogger $logger,
                        IConfig $config,
                Severity: Minor
                Found in apps/provisioning_api/lib/Users.php - About 45 mins to fix

                  Function getUser has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function getUser($parameters) {
                          $userId = $parameters['userid'];
                  
                          // Check if user is logged in
                          $currentLoggedInUser = $this->userSession->getUser();
                  Severity: Minor
                  Found in apps/provisioning_api/lib/Users.php - About 35 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Function addToGroup has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function addToGroup($parameters) {
                          // Check if user is logged in
                          $user = $this->userSession->getUser();
                          if ($user === null) {
                              return new Result(null, API::RESPOND_UNAUTHORISED);
                  Severity: Minor
                  Found in apps/provisioning_api/lib/Users.php - About 35 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Function deleteUser has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function deleteUser($parameters) {
                          // Check if user is logged in
                          $currentLoggedInUser = $this->userSession->getUser();
                          if ($currentLoggedInUser === null) {
                              return new Result(null, API::RESPOND_UNAUTHORISED);
                  Severity: Minor
                  Found in apps/provisioning_api/lib/Users.php - About 35 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Function getUserSubAdminGroups has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function getUserSubAdminGroups($parameters) {
                          // Check if user is logged in
                          $currentLoggedInUser = $this->userSession->getUser();
                          if ($currentLoggedInUser === null) {
                              return new Result(null, API::RESPOND_UNAUTHORISED);
                  Severity: Minor
                  Found in apps/provisioning_api/lib/Users.php - About 35 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Avoid too many return statements within this method.
                  Open

                              return new Result(null, 103, 'Unknown error occurred');
                  Severity: Major
                  Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return new Result(null, 100);
                    Severity: Major
                    Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                          return new Result(null, 105, 'Cannot remove yourself from this group as you are a SubAdmin');
                      Severity: Major
                      Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return new Result(null, 100);
                        Severity: Major
                        Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return new Result(null, 997);
                          Severity: Major
                          Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return new Result(null, 103);
                            Severity: Major
                            Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                          return new Result(null, 101, $e->getMessage());
                              Severity: Major
                              Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                    return new Result(null, 105, 'Cannot remove yourself from the admin group');
                                Severity: Major
                                Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                      return new Result(null, 102);
                                  Severity: Major
                                  Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                    return new Result(null, 103);
                                    Severity: Major
                                    Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                              return new Result(null, 100);
                                      Severity: Major
                                      Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                            return new Result(null, 403, $e->getMessage());
                                        Severity: Major
                                        Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                  return new Result(null, 100);
                                          Severity: Major
                                          Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                            return new Result(null, 106, 'no group specified (required for subadmins)');
                                            Severity: Major
                                            Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                          return new Result(null, 103, 'Unknown error occurred');
                                              Severity: Major
                                              Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                                        return new Result(null, 103, "Invalid quota value {$parameters['_put']['value']}");
                                                Severity: Major
                                                Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                              return new Result(null, 104);
                                                  Severity: Major
                                                  Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

                                                                return new Result(null, 100);
                                                    Severity: Major
                                                    Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                  return new Result(null, 101);
                                                      Severity: Major
                                                      Found in apps/provisioning_api/lib/Users.php - About 30 mins to fix

                                                        Function addSubAdmin has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                        Open

                                                            public function addSubAdmin($parameters) {
                                                                $group = $this->groupManager->get($_POST['groupid']);
                                                                $user = $this->userManager->get($parameters['userid']);
                                                        
                                                                // Check if the user exists
                                                        Severity: Minor
                                                        Found in apps/provisioning_api/lib/Users.php - About 25 mins to fix

                                                        Cognitive Complexity

                                                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                                        A method's cognitive complexity is based on a few simple rules:

                                                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                                        • Code is considered more complex for each "break in the linear flow of the code"
                                                        • Code is considered more complex when "flow breaking structures are nested"

                                                        Further reading

                                                        There are no issues that match your filters.

                                                        Category
                                                        Status