wikimedia/mediawiki-core

View on GitHub
includes/session/SessionBackend.php

Summary

Maintainability
F
3 days
Test Coverage

File SessionBackend.php has 524 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

    Function save has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

        public function save( $closing = false ) {
            $anon = $this->user->isAnon();
    
            if ( !$anon && $this->provider->getManager()->isUserSessionPrevented( $this->user->getName() ) ) {
                $this->logger->debug(
    Severity: Minor
    Found in includes/session/SessionBackend.php - About 4 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

    SessionBackend has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    final class SessionBackend {
        /** @var SessionId */
        private $id;
    
        /** @var bool */
    Severity: Minor
    Found in includes/session/SessionBackend.php - About 4 hrs to fix

      Method save has 111 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function save( $closing = false ) {
              $anon = $this->user->isAnon();
      
              if ( !$anon && $this->provider->getManager()->isUserSessionPrevented( $this->user->getName() ) ) {
                  $this->logger->debug(
      Severity: Major
      Found in includes/session/SessionBackend.php - About 4 hrs to fix

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

            public function __construct(
                SessionId $id, SessionInfo $info, CachedBagOStuff $store, LoggerInterface $logger,
                HookContainer $hookContainer, $lifetime
            ) {
                $phpSessionHandling = MediaWikiServices::getInstance()->getMainConfig()
        Severity: Major
        Found in includes/session/SessionBackend.php - About 2 hrs to fix

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

              public function __construct(
                  SessionId $id, SessionInfo $info, CachedBagOStuff $store, LoggerInterface $logger,
                  HookContainer $hookContainer, $lifetime
              ) {
                  $phpSessionHandling = MediaWikiServices::getInstance()->getMainConfig()
          Severity: Minor
          Found in includes/session/SessionBackend.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 logPersistenceChange has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function logPersistenceChange( WebRequest $request, bool $persist ) {
                  if ( !$this->isPersistent() && !$persist ) {
                      // FIXME SessionManager calls unpersistSession() on anonymous requests (and the cookie
                      //   filtering in WebResponse makes it a noop). Skip those.
                      return;
          Severity: Minor
          Found in includes/session/SessionBackend.php - About 1 hr to fix

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

                    SessionId $id, SessionInfo $info, CachedBagOStuff $store, LoggerInterface $logger,
                    HookContainer $hookContainer, $lifetime
            Severity: Minor
            Found in includes/session/SessionBackend.php - About 45 mins to fix

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

                  private function logPersistenceChange( WebRequest $request, bool $persist ) {
                      if ( !$this->isPersistent() && !$persist ) {
                          // FIXME SessionManager calls unpersistSession() on anonymous requests (and the cookie
                          //   filtering in WebResponse makes it a noop). Skip those.
                          return;
              Severity: Minor
              Found in includes/session/SessionBackend.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 resetId has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function resetId() {
                      if ( $this->provider->persistsSessionId() ) {
                          $oldId = (string)$this->id;
                          $restart = $this->usePhpSessionHandling && $oldId === session_id() &&
                              PHPSessionHandler::isEnabled();
              Severity: Minor
              Found in includes/session/SessionBackend.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