owncloud/core

View on GitHub
lib/private/User/Session.php

Summary

Maintainability
F
5 days
Test Coverage

File Session.php has 775 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
 * @author Bernhard Posselt <dev@bernhard-posselt.com>
 * @author Christoph Wurst <christoph@owncloud.com>
Severity: Major
Found in lib/private/User/Session.php - About 1 day to fix

    Session has 44 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Session implements IUserSession, Emitter {
        use EventEmitterTrait;
        /** @var IUserManager | PublicEmitter $manager */
        private $manager;
    
    
    Severity: Minor
    Found in lib/private/User/Session.php - About 6 hrs to fix

      Method checkTokenCredentials has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function checkTokenCredentials(IToken $dbToken, $token) {
              // Check whether login credentials are still valid and the user was not disabled
              // This check is performed each 5 minutes per default
              // However, we try to read last_check_timeout from the appconfig table so the
              // administrator could change this 5 minutes timeout
      Severity: Minor
      Found in lib/private/User/Session.php - About 1 hr to fix

        Method loginWithApache has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function loginWithApache(IApacheBackend $apacheBackend) {
                $uidAndBackend = $apacheBackend->getCurrentUserId();
                if (\is_array($uidAndBackend)
                    && \count($uidAndBackend) === 2
                    && $uidAndBackend[0] !== ''
        Severity: Minor
        Found in lib/private/User/Session.php - About 1 hr to fix

          Function verifyAuthHeaders has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              public function verifyAuthHeaders($request) {
                  $shallLogout = false;
                  try {
                      $lastUser = null;
                      foreach ($this->getAuthModules(true) as $module) {
          Severity: Minor
          Found in lib/private/User/Session.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 validateToken has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function validateToken($token, $user = null) {
                  try {
                      $dbToken = $this->tokenProvider->getToken($token);
                  } catch (InvalidTokenException $ex) {
                      $this->logger->debug(
          Severity: Minor
          Found in lib/private/User/Session.php - About 1 hr to fix

            Function logClientIn has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                public function logClientIn($user, $password, IRequest $request) {
                    $isTokenPassword = $this->isTokenPassword($password);
                    if ($user === null || \trim($user) === '') {
                        throw new \InvalidArgumentException('$user cannot be empty');
                    }
            Severity: Minor
            Found in lib/private/User/Session.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 loginInOwnCloud has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function loginInOwnCloud($loginType, $user, $password, $options = []) {
                    $login = $user->getUID();
            
                    // check the login policies first. It will throw a LoginException if needed
                    // The LoginPolicyManager can't be injected due to cyclic dependency
            Severity: Minor
            Found in lib/private/User/Session.php - About 1 hr to fix

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

                  public function loginWithApache(IApacheBackend $apacheBackend) {
                      $uidAndBackend = $apacheBackend->getCurrentUserId();
                      if (\is_array($uidAndBackend)
                          && \count($uidAndBackend) === 2
                          && $uidAndBackend[0] !== ''
              Severity: Minor
              Found in lib/private/User/Session.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 9 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                      IUserManager $manager,
                      ISession $session,
                      ITimeFactory $timeFactory,
                      IProvider $tokenProvider,
                      IConfig $config,
              Severity: Major
              Found in lib/private/User/Session.php - About 1 hr to fix

                Method logClientIn has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function logClientIn($user, $password, IRequest $request) {
                        $isTokenPassword = $this->isTokenPassword($password);
                        if ($user === null || \trim($user) === '') {
                            throw new \InvalidArgumentException('$user cannot be empty');
                        }
                Severity: Minor
                Found in lib/private/User/Session.php - About 1 hr to fix

                  Method loginWithCookie has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function loginWithCookie($uid, $currentToken) {
                          $this->logger->debug(
                              'regenerating session id for uid {uid}, currentToken {currentToken}',
                              ['app' => __METHOD__, 'uid' => $uid, 'currentToken' => $currentToken]
                          );
                  Severity: Minor
                  Found in lib/private/User/Session.php - About 1 hr to fix

                    Function loginInOwnCloud has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function loginInOwnCloud($loginType, $user, $password, $options = []) {
                            $login = $user->getUID();
                    
                            // check the login policies first. It will throw a LoginException if needed
                            // The LoginPolicyManager can't be injected due to cyclic dependency
                    Severity: Minor
                    Found in lib/private/User/Session.php - About 55 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 clearRememberMeTokensForLoggedInUser has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function clearRememberMeTokensForLoggedInUser($targetToken) {
                            $user = $this->getUser();
                            $uid = $user->getUID();
                            if ($targetToken !== null) {
                                $hashedToken = \hash('snefru', $targetToken);
                    Severity: Minor
                    Found in lib/private/User/Session.php - About 55 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 tryAuthModuleLogin has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function tryAuthModuleLogin(IRequest $request) {
                            foreach ($this->getAuthModules(false) as $authModule) {
                                $user = $authModule->auth($request);
                                if ($user !== null) {
                                    if (!$user->isEnabled()) {
                    Severity: Minor
                    Found in lib/private/User/Session.php - About 55 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 getAuthModules has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected function getAuthModules($includeBuiltIn) {
                            if ($includeBuiltIn) {
                                yield new TokenAuthModule($this->session, $this->tokenProvider, $this->manager);
                            }
                    
                    
                    Severity: Minor
                    Found in lib/private/User/Session.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 isTwoFactorEnforced has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected function isTwoFactorEnforced($username) {
                            $handled = false;
                            // the $handled var will be sent as reference so the listeners can use it as a flag
                            // in order to know if the event has been processed already or not.
                            Util::emitHook(
                    Severity: Minor
                    Found in lib/private/User/Session.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 validateSession has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function validateSession() {
                            $sessionUser = $this->getUser();
                            if (!$sessionUser) {
                                return;
                            }
                    Severity: Minor
                    Found in lib/private/User/Session.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 prepareUserLogin has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function prepareUserLogin($firstTimeLogin = false) {
                            // TODO: mock/inject/use non-static
                            // Refresh the token
                            \OC::$server->getCsrfTokenManager()->refreshToken();
                            //we need to pass the user name, which may differ from login name
                    Severity: Minor
                    Found in lib/private/User/Session.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 false;
                    Severity: Major
                    Found in lib/private/User/Session.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return $loginOk;
                      Severity: Major
                      Found in lib/private/User/Session.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return true;
                        Severity: Major
                        Found in lib/private/User/Session.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return false;
                          Severity: Major
                          Found in lib/private/User/Session.php - About 30 mins to fix

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

                                public function tryBasicAuthLogin(IRequest $request) {
                                    if (!empty($request->server['PHP_AUTH_USER']) && !empty($request->server['PHP_AUTH_PW'])) {
                                        try {
                                            if ($this->logClientIn($request->server['PHP_AUTH_USER'], $request->server['PHP_AUTH_PW'], $request)) {
                                                /**
                            Severity: Minor
                            Found in lib/private/User/Session.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

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

                                public function tryTokenLogin(IRequest $request) {
                                    $authHeader = $request->getHeader('Authorization');
                                    if ($authHeader === null || \strpos($authHeader, 'token ') === false) {
                                        // No auth header, let's try session id
                                        try {
                            Severity: Minor
                            Found in lib/private/User/Session.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

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

                                public function getUser() {
                                    // FIXME: This is a quick'n dirty work-around for the incognito mode as
                                    // described at https://github.com/owncloud/core/pull/12912#issuecomment-67391155
                                    if (OC_User::isIncognitoMode()) {
                                        return null;
                            Severity: Minor
                            Found in lib/private/User/Session.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

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

                                private function checkTokenCredentials(IToken $dbToken, $token) {
                                    // Check whether login credentials are still valid and the user was not disabled
                                    // This check is performed each 5 minutes per default
                                    // However, we try to read last_check_timeout from the appconfig table so the
                                    // administrator could change this 5 minutes timeout
                            Severity: Minor
                            Found in lib/private/User/Session.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