wikimedia/mediawiki-core

View on GitHub
includes/session/SessionManager.php

Summary

Maintainability
F
1 wk
Test Coverage

Function loadSessionInfoFromStore has a Cognitive Complexity of 88 (exceeds 5 allowed). Consider refactoring.
Open

    private function loadSessionInfoFromStore( SessionInfo &$info, WebRequest $request ) {
        $key = $this->store->makeKey( 'MWSession', $info->getId() );
        $blob = $this->store->get( $key );

        // If we got data from the store and the SessionInfo says to force use,
Severity: Minor
Found in includes/session/SessionManager.php - About 1 day 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

File SessionManager.php has 748 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * MediaWiki\Session entry point
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Major
Found in includes/session/SessionManager.php - About 1 day to fix

    Method loadSessionInfoFromStore has 234 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function loadSessionInfoFromStore( SessionInfo &$info, WebRequest $request ) {
            $key = $this->store->makeKey( 'MWSession', $info->getId() );
            $blob = $this->store->get( $key );
    
            // If we got data from the store and the SessionInfo says to force use,
    Severity: Major
    Found in includes/session/SessionManager.php - About 1 day to fix

      Function getEmptySessionInternal has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          private function getEmptySessionInternal( WebRequest $request = null, $id = null ) {
              if ( $id !== null ) {
                  if ( !self::validateSessionId( $id ) ) {
                      throw new \InvalidArgumentException( 'Invalid session ID' );
                  }
      Severity: Minor
      Found in includes/session/SessionManager.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

      SessionManager has 29 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class SessionManager implements SessionManagerInterface {
          /** @var SessionManager|null */
          private static $instance = null;
      
          /** @var Session|null */
      Severity: Minor
      Found in includes/session/SessionManager.php - About 3 hrs to fix

        Function getSessionInfoForRequest has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
        Open

            private function getSessionInfoForRequest( WebRequest $request ) {
                // Call all providers to fetch "the" session
                $infos = [];
                foreach ( $this->getProviders() as $provider ) {
                    $info = $provider->provideSessionInfo( $request );
        Severity: Minor
        Found in includes/session/SessionManager.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

        Method logPotentialSessionLeakage has 64 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function logPotentialSessionLeakage( Session $session = null ) {
                $proxyLookup = MediaWikiServices::getInstance()->getProxyLookup();
                $session = $session ?: self::getGlobalSession();
                $suspiciousIpExpiry = $this->config->get( MainConfigNames::SuspiciousIpExpiry );
        
        
        Severity: Major
        Found in includes/session/SessionManager.php - About 2 hrs to fix

          Method getEmptySessionInternal has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function getEmptySessionInternal( WebRequest $request = null, $id = null ) {
                  if ( $id !== null ) {
                      if ( !self::validateSessionId( $id ) ) {
                          throw new \InvalidArgumentException( 'Invalid session ID' );
                      }
          Severity: Major
          Found in includes/session/SessionManager.php - About 2 hrs to fix

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

                public function __construct( $options = [] ) {
                    $services = MediaWikiServices::getInstance();
                    if ( isset( $options['config'] ) ) {
                        $this->config = $options['config'];
                        if ( !$this->config instanceof Config ) {
            Severity: Minor
            Found in includes/session/SessionManager.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 getSessionInfoForRequest has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function getSessionInfoForRequest( WebRequest $request ) {
                    // Call all providers to fetch "the" session
                    $infos = [];
                    foreach ( $this->getProviders() as $provider ) {
                        $info = $provider->provideSessionInfo( $request );
            Severity: Minor
            Found in includes/session/SessionManager.php - About 1 hr to fix

              Method getSessionFromInfo has 42 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function getSessionFromInfo( SessionInfo $info, WebRequest $request ) {
                      // @codeCoverageIgnoreStart
                      if ( defined( 'MW_NO_SESSION' ) ) {
                          $ep = defined( 'MW_ENTRY_POINT' ) ? MW_ENTRY_POINT : 'this';
              
              
              Severity: Minor
              Found in includes/session/SessionManager.php - About 1 hr to fix

                Method __construct has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function __construct( $options = [] ) {
                        $services = MediaWikiServices::getInstance();
                        if ( isset( $options['config'] ) ) {
                            $this->config = $options['config'];
                            if ( !$this->config instanceof Config ) {
                Severity: Minor
                Found in includes/session/SessionManager.php - About 1 hr to fix

                  Function getSessionFromInfo has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function getSessionFromInfo( SessionInfo $info, WebRequest $request ) {
                          // @codeCoverageIgnoreStart
                          if ( defined( 'MW_NO_SESSION' ) ) {
                              $ep = defined( 'MW_ENTRY_POINT' ) ? MW_ENTRY_POINT : 'this';
                  
                  
                  Severity: Minor
                  Found in includes/session/SessionManager.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

                  Function logPotentialSessionLeakage has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function logPotentialSessionLeakage( Session $session = null ) {
                          $proxyLookup = MediaWikiServices::getInstance()->getProxyLookup();
                          $session = $session ?: self::getGlobalSession();
                          $suspiciousIpExpiry = $this->config->get( MainConfigNames::SuspiciousIpExpiry );
                  
                  
                  Severity: Minor
                  Found in includes/session/SessionManager.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 getSessionById has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function getSessionById( $id, $create = false, WebRequest $request = null ) {
                          if ( !self::validateSessionId( $id ) ) {
                              throw new \InvalidArgumentException( 'Invalid session ID' );
                          }
                          if ( !$request ) {
                  Severity: Minor
                  Found in includes/session/SessionManager.php - About 1 hr to fix

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

                        public function getSessionById( $id, $create = false, WebRequest $request = null ) {
                            if ( !self::validateSessionId( $id ) ) {
                                throw new \InvalidArgumentException( 'Invalid session ID' );
                            }
                            if ( !$request ) {
                    Severity: Minor
                    Found in includes/session/SessionManager.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

                    Function getVaryHeaders has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function getVaryHeaders() {
                            // @codeCoverageIgnoreStart
                            if ( defined( 'MW_NO_SESSION' ) && MW_NO_SESSION !== 'warn' ) {
                                return [];
                            }
                    Severity: Minor
                    Found in includes/session/SessionManager.php - About 45 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 getGlobalSession has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function getGlobalSession(): Session {
                            if ( !PHPSessionHandler::isEnabled() ) {
                                $id = '';
                            } else {
                                $id = session_id();
                    Severity: Minor
                    Found in includes/session/SessionManager.php - About 45 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 $failHandler();
                    Severity: Major
                    Found in includes/session/SessionManager.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return $failHandler();
                      Severity: Major
                      Found in includes/session/SessionManager.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                                return $failHandler();
                        Severity: Major
                        Found in includes/session/SessionManager.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                              return $failHandler();
                          Severity: Major
                          Found in includes/session/SessionManager.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                                return $failHandler();
                            Severity: Major
                            Found in includes/session/SessionManager.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                          return $failHandler();
                              Severity: Major
                              Found in includes/session/SessionManager.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                return $failHandler();
                                Severity: Major
                                Found in includes/session/SessionManager.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                      return $failHandler();
                                  Severity: Major
                                  Found in includes/session/SessionManager.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                            return $failHandler();
                                    Severity: Major
                                    Found in includes/session/SessionManager.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                      return $failHandler();
                                      Severity: Major
                                      Found in includes/session/SessionManager.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                            return $failHandler();
                                        Severity: Major
                                        Found in includes/session/SessionManager.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                          return $failHandler();
                                          Severity: Major
                                          Found in includes/session/SessionManager.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                        return $failHandler();
                                            Severity: Major
                                            Found in includes/session/SessionManager.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                                      return $failHandler();
                                              Severity: Major
                                              Found in includes/session/SessionManager.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                                        return $failHandler();
                                                Severity: Major
                                                Found in includes/session/SessionManager.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                          return true;
                                                  Severity: Major
                                                  Found in includes/session/SessionManager.php - About 30 mins to fix

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

                                                        protected function getProviders() {
                                                            if ( $this->sessionProviders === null ) {
                                                                $this->sessionProviders = [];
                                                                $objectFactory = MediaWikiServices::getInstance()->getObjectFactory();
                                                                foreach ( $this->config->get( MainConfigNames::SessionProviders ) as $spec ) {
                                                    Severity: Minor
                                                    Found in includes/session/SessionManager.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