wikimedia/mediawiki-core

View on GitHub
includes/libs/objectcache/RedisBagOStuff.php

Summary

Maintainability
F
3 days
Test Coverage

File RedisBagOStuff.php has 371 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Object caching using Redis (http://redis.io/).
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Minor
Found in includes/libs/objectcache/RedisBagOStuff.php - About 4 hrs to fix

    Function getConnectionsForKeys has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function getConnectionsForKeys( array $keys ) {
            $keysByServer = [];
            $connByServer = [];
            $success = true;
            foreach ( $keys as $key ) {
    Severity: Minor
    Found in includes/libs/objectcache/RedisBagOStuff.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

    Function doGetMulti has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function doGetMulti( array $keys, $flags = 0 ) {
            $blobsFound = [];
    
            [ $keysByServer, $connByServer ] = $this->getConnectionsForKeys( $keys );
            foreach ( $keysByServer as $server => $batchKeys ) {
    Severity: Minor
    Found in includes/libs/objectcache/RedisBagOStuff.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 doGetMulti has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function doGetMulti( array $keys, $flags = 0 ) {
            $blobsFound = [];
    
            [ $keysByServer, $connByServer ] = $this->getConnectionsForKeys( $keys );
            foreach ( $keysByServer as $server => $batchKeys ) {
    Severity: Minor
    Found in includes/libs/objectcache/RedisBagOStuff.php - About 1 hr to fix

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

          public function doChangeTTLMulti( array $keys, $exptime, $flags = 0 ) {
              $relative = $this->isRelativeExpiration( $exptime );
              $op = ( $exptime == self::TTL_INDEFINITE )
                  ? 'persist'
                  : ( $relative ? 'expire' : 'expireAt' );
      Severity: Minor
      Found in includes/libs/objectcache/RedisBagOStuff.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 doSetMulti has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function doSetMulti( array $data, $exptime = 0, $flags = 0 ) {
              $ttl = $this->getExpirationAsTTL( $exptime );
              $op = $ttl ? 'setex' : 'set';
      
              $keys = array_keys( $data );
      Severity: Minor
      Found in includes/libs/objectcache/RedisBagOStuff.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 getConnectionsForKeys has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function getConnectionsForKeys( array $keys ) {
              $keysByServer = [];
              $connByServer = [];
              $success = true;
              foreach ( $keys as $key ) {
      Severity: Minor
      Found in includes/libs/objectcache/RedisBagOStuff.php - About 1 hr to fix

        Method doSetMulti has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function doSetMulti( array $data, $exptime = 0, $flags = 0 ) {
                $ttl = $this->getExpirationAsTTL( $exptime );
                $op = $ttl ? 'setex' : 'set';
        
                $keys = array_keys( $data );
        Severity: Minor
        Found in includes/libs/objectcache/RedisBagOStuff.php - About 1 hr to fix

          Method doChangeTTLMulti has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function doChangeTTLMulti( array $keys, $exptime, $flags = 0 ) {
                  $relative = $this->isRelativeExpiration( $exptime );
                  $op = ( $exptime == self::TTL_INDEFINITE )
                      ? 'persist'
                      : ( $relative ? 'expire' : 'expireAt' );
          Severity: Minor
          Found in includes/libs/objectcache/RedisBagOStuff.php - About 1 hr to fix

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

                protected function doIncrWithInit( $key, $exptime, $step, $init, $flags ) {
                    $conn = $this->getConnection( $key );
                    if ( !$conn ) {
                        return false;
                    }
            Severity: Minor
            Found in includes/libs/objectcache/RedisBagOStuff.php - About 1 hr to fix

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

                  protected function doGet( $key, $flags = 0, &$casToken = null ) {
                      $getToken = ( $casToken === self::PASS_BY_REF );
                      $casToken = null;
              
                      $conn = $this->getConnection( $key );
              Severity: Minor
              Found in includes/libs/objectcache/RedisBagOStuff.php - About 1 hr to fix

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

                    protected function doDeleteMulti( array $keys, $flags = 0 ) {
                        [ $keysByServer, $connByServer, $result ] = $this->getConnectionsForKeys( $keys );
                        foreach ( $keysByServer as $server => $batchKeys ) {
                            $conn = $connByServer[$server];
                
                
                Severity: Minor
                Found in includes/libs/objectcache/RedisBagOStuff.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

                Method doIncrWithInit has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    protected function doIncrWithInit( $key, $exptime, $step, $init, $flags ) {
                Severity: Minor
                Found in includes/libs/objectcache/RedisBagOStuff.php - About 35 mins to fix

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

                      protected function doGet( $key, $flags = 0, &$casToken = null ) {
                          $getToken = ( $casToken === self::PASS_BY_REF );
                          $casToken = null;
                  
                          $conn = $this->getConnection( $key );
                  Severity: Minor
                  Found in includes/libs/objectcache/RedisBagOStuff.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