wikimedia/mediawiki-core

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

Summary

Maintainability
F
4 days
Test Coverage

File MediumSpecificBagOStuff.php has 586 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Storage medium specific cache for storing items.
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Major
Found in includes/libs/objectcache/MediumSpecificBagOStuff.php - About 1 day to fix

    MediumSpecificBagOStuff has 51 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class MediumSpecificBagOStuff extends BagOStuff {
        /** @var array<string,array> Map of (key => (class LOCK_* constant => value) */
        protected $locks = [];
        /** @var int Bytes; chunk size of segmented cache values */
        protected $segmentationSize;
    Severity: Major
    Found in includes/libs/objectcache/MediumSpecificBagOStuff.php - About 7 hrs to fix

      Method updateOpStats has 57 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function updateOpStats( string $op, array $keyInfo ) {
              $deltasByMetric = [];
      
              foreach ( $keyInfo as $indexOrKey => $keyOrSizes ) {
                  if ( is_array( $keyOrSizes ) ) {
      Severity: Major
      Found in includes/libs/objectcache/MediumSpecificBagOStuff.php - About 2 hrs to fix

        Function updateOpStats has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function updateOpStats( string $op, array $keyInfo ) {
                $deltasByMetric = [];
        
                foreach ( $keyInfo as $indexOrKey => $keyOrSizes ) {
                    if ( is_array( $keyOrSizes ) ) {
        Severity: Minor
        Found in includes/libs/objectcache/MediumSpecificBagOStuff.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 mergeViaCas has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            final protected function mergeViaCas( $key, callable $callback, $exptime, $attempts, $flags ) {
                $attemptsLeft = $attempts;
                do {
                    $token = self::PASS_BY_REF;
                    // Get the old value and CAS token from cache
        Severity: Minor
        Found in includes/libs/objectcache/MediumSpecificBagOStuff.php - About 1 hr to fix

          Method makeValueOrSegmentList has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              final protected function makeValueOrSegmentList( $key, $value, $exptime, $flags, &$ok ) {
                  $entry = $value;
                  $ok = true;
          
                  if ( $this->useSegmentationWrapper( $value, $flags ) ) {
          Severity: Minor
          Found in includes/libs/objectcache/MediumSpecificBagOStuff.php - About 1 hr to fix

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

                final protected function mergeViaCas( $key, callable $callback, $exptime, $attempts, $flags ) {
                    $attemptsLeft = $attempts;
                    do {
                        $token = self::PASS_BY_REF;
                        // Get the old value and CAS token from cache
            Severity: Minor
            Found in includes/libs/objectcache/MediumSpecificBagOStuff.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 useSegmentationWrapper has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                private function useSegmentationWrapper( $value, $flags ) {
                    if (
                        $this->segmentationSize === INF ||
                        !$this->fieldHasFlags( $flags, self::WRITE_ALLOW_SEGMENTS )
                    ) {
            Severity: Minor
            Found in includes/libs/objectcache/MediumSpecificBagOStuff.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 doLock has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function doLock( $key, $timeout, $exptime ) {
                    $lockTsUnix = null;
            
                    $fname = __METHOD__;
                    $loop = new WaitConditionLoop(
            Severity: Minor
            Found in includes/libs/objectcache/MediumSpecificBagOStuff.php - About 1 hr to fix

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

                  public function unlock( $key ) {
                      $released = false;
              
                      if ( isset( $this->locks[$key] ) ) {
                          if ( --$this->locks[$key][self::LOCK_DEPTH] > 0 ) {
              Severity: Minor
              Found in includes/libs/objectcache/MediumSpecificBagOStuff.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

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

                  public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
              Severity: Minor
              Found in includes/libs/objectcache/MediumSpecificBagOStuff.php - About 35 mins to fix

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

                    final protected function mergeViaCas( $key, callable $callback, $exptime, $attempts, $flags ) {
                Severity: Minor
                Found in includes/libs/objectcache/MediumSpecificBagOStuff.php - About 35 mins to fix

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

                      protected function cas( $casToken, $key, $value, $exptime = 0, $flags = 0 ) {
                  Severity: Minor
                  Found in includes/libs/objectcache/MediumSpecificBagOStuff.php - About 35 mins to fix

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

                        final protected function makeValueOrSegmentList( $key, $value, $exptime, $flags, &$ok ) {
                    Severity: Minor
                    Found in includes/libs/objectcache/MediumSpecificBagOStuff.php - About 35 mins to fix

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

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

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

                            protected function doCas( $casToken, $key, $value, $exptime = 0, $flags = 0 ) {
                        Severity: Minor
                        Found in includes/libs/objectcache/MediumSpecificBagOStuff.php - About 35 mins to fix

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

                              public function incrWithInit( $key, $exptime, $step = 1, $init = null, $flags = 0 ) {
                          Severity: Minor
                          Found in includes/libs/objectcache/MediumSpecificBagOStuff.php - About 35 mins to fix

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

                                final protected function resolveSegments( $key, $mainValue ) {
                                    if ( SerializedValueContainer::isSegmented( $mainValue ) ) {
                                        $orderedKeys = array_map(
                                            function ( $segmentHash ) use ( $key ) {
                                                return $this->makeGlobalKey( self::SEGMENT_COMPONENT, $key, $segmentHash );
                            Severity: Minor
                            Found in includes/libs/objectcache/MediumSpecificBagOStuff.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 checkIterableMapSerializability has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                private function checkIterableMapSerializability( $value, $key ) {
                                    foreach ( $value as $index => $entry ) {
                                        if ( is_object( $entry ) ) {
                                            // Note that Closure instances count as objects
                                            if (
                            Severity: Minor
                            Found in includes/libs/objectcache/MediumSpecificBagOStuff.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 makeValueOrSegmentList has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                final protected function makeValueOrSegmentList( $key, $value, $exptime, $flags, &$ok ) {
                                    $entry = $value;
                                    $ok = true;
                            
                                    if ( $this->useSegmentationWrapper( $value, $flags ) ) {
                            Severity: Minor
                            Found in includes/libs/objectcache/MediumSpecificBagOStuff.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 doChangeTTL has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                protected function doChangeTTL( $key, $exptime, $flags ) {
                                    // @TODO: the use of lock() assumes that all other relevant sets() use a lock
                                    if ( !$this->lock( $key, 0 ) ) {
                                        return false;
                                    }
                            Severity: Minor
                            Found in includes/libs/objectcache/MediumSpecificBagOStuff.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 lock has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public function lock( $key, $timeout = 6, $exptime = 6, $rclass = '' ) {
                                    $exptime = min( $exptime ?: INF, self::TTL_DAY );
                            
                                    $acquired = false;
                            
                            
                            Severity: Minor
                            Found in includes/libs/objectcache/MediumSpecificBagOStuff.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 $this->deleteMulti( $orderedKeys, $flags & ~self::WRITE_PRUNE_SEGMENTS );
                            Severity: Major
                            Found in includes/libs/objectcache/MediumSpecificBagOStuff.php - About 30 mins to fix

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

                                  public function getMulti( array $keys, $flags = 0 ) {
                                      $foundByKey = $this->doGetMulti( $keys, $flags );
                              
                                      $res = [];
                                      foreach ( $keys as $key ) {
                              Severity: Minor
                              Found in includes/libs/objectcache/MediumSpecificBagOStuff.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