wikimedia/mediawiki-core

View on GitHub
includes/language/LocalisationCache.php

Summary

Maintainability
F
1 wk
Test Coverage

Function recache has a Cognitive Complexity of 113 (exceeds 5 allowed). Consider refactoring.
Open

    public function recache( $code ) {
        if ( !$code ) {
            throw new InvalidArgumentException( "Invalid language code requested" );
        }
        $this->recachedLangs[ $code ] = true;
Severity: Minor
Found in includes/language/LocalisationCache.php - About 2 days 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 LocalisationCache.php has 770 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
Severity: Major
Found in includes/language/LocalisationCache.php - About 1 day to fix

    Method recache has 189 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function recache( $code ) {
            if ( !$code ) {
                throw new InvalidArgumentException( "Invalid language code requested" );
            }
            $this->recachedLangs[ $code ] = true;
    Severity: Major
    Found in includes/language/LocalisationCache.php - About 7 hrs to fix

      Function initLanguage has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
      Open

          private function initLanguage( $code ) {
              if ( isset( $this->initialisedLangs[$code] ) ) {
                  return;
              }
      
      
      Severity: Minor
      Found in includes/language/LocalisationCache.php - About 5 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

      LocalisationCache has 30 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class LocalisationCache {
          public const VERSION = 5;
      
          /** @var ServiceOptions */
          private $options;
      Severity: Minor
      Found in includes/language/LocalisationCache.php - About 3 hrs to fix

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

            private function loadCoreData( string $code ) {
                if ( !$code ) {
                    throw new InvalidArgumentException( "Invalid language code requested" );
                }
                if ( $this->coreDataLoaded[$code] ?? false ) {
        Severity: Minor
        Found in includes/language/LocalisationCache.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 initLanguage has 65 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function initLanguage( $code ) {
                if ( isset( $this->initialisedLangs[$code] ) ) {
                    return;
                }
        
        
        Severity: Major
        Found in includes/language/LocalisationCache.php - About 2 hrs to fix

          Function loadItem has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              private function loadItem( $code, $key ) {
                  if ( isset( $this->loadedItems[$code][$key] ) ) {
                      return;
                  }
          
          
          Severity: Minor
          Found in includes/language/LocalisationCache.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 loadCoreData has 55 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function loadCoreData( string $code ) {
                  if ( !$code ) {
                      throw new InvalidArgumentException( "Invalid language code requested" );
                  }
                  if ( $this->coreDataLoaded[$code] ?? false ) {
          Severity: Major
          Found in includes/language/LocalisationCache.php - About 2 hrs to fix

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

                protected function readPHPFile( $_fileName, $_fileType ) {
                    include $_fileName;
            
                    $data = [];
                    if ( $_fileType == 'core' ) {
            Severity: Minor
            Found in includes/language/LocalisationCache.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

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

                private function mergeItem( $key, &$value, $fallbackValue ) {
                    if ( $value !== null ) {
                        if ( $fallbackValue !== null ) {
                            if ( in_array( $key, self::MERGEABLE_MAP_KEYS ) ) {
                                $value += $fallbackValue;
            Severity: Minor
            Found in includes/language/LocalisationCache.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 loadItem has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function loadItem( $code, $key ) {
                    if ( isset( $this->loadedItems[$code][$key] ) ) {
                        return;
                    }
            
            
            Severity: Minor
            Found in includes/language/LocalisationCache.php - About 1 hr to fix

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

                  private static function loadPluralFile( $fileName ) {
                      // Use file_get_contents instead of DOMDocument::load (T58439)
                      $xml = file_get_contents( $fileName );
                      if ( !$xml ) {
                          throw new RuntimeException( "Unable to read plurals file $fileName" );
              Severity: Minor
              Found in includes/language/LocalisationCache.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 loadSubitem has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function loadSubitem( $code, $key, $subkey ) {
                      if ( !in_array( $key, self::SPLIT_KEYS ) ) {
                          $this->loadItem( $code, $key );
              
                          return;
              Severity: Minor
              Found in includes/language/LocalisationCache.php - About 1 hr to fix

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

                    public static function getStoreFromConf( array $conf, $fallbackCacheDir ): LCStore {
                        $storeArg = [];
                        $storeArg['directory'] =
                            $conf['storeDirectory'] ?: $fallbackCacheDir;
                
                
                Severity: Minor
                Found in includes/language/LocalisationCache.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 loadSubitem has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function loadSubitem( $code, $key, $subkey ) {
                        if ( !in_array( $key, self::SPLIT_KEYS ) ) {
                            $this->loadItem( $code, $key );
                
                            return;
                Severity: Minor
                Found in includes/language/LocalisationCache.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 __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                        ServiceOptions $options,
                        LCStore $store,
                        LoggerInterface $logger,
                        array $clearStoreCallbacks,
                        LanguageNameUtils $langNameUtils,
                Severity: Minor
                Found in includes/language/LocalisationCache.php - About 45 mins to fix

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

                      public function isExpired( $code ) {
                          if ( $this->options->get( 'forceRecache' ) && !isset( $this->recachedLangs[$code] ) ) {
                              $this->logger->debug( __METHOD__ . "($code): forced reload" );
                  
                              return true;
                  Severity: Minor
                  Found in includes/language/LocalisationCache.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 readJSONFile has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private function readJSONFile( $fileName ) {
                          if ( !is_readable( $fileName ) ) {
                              return [];
                          }
                  
                  
                  Severity: Minor
                  Found in includes/language/LocalisationCache.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

                  There are no issues that match your filters.

                  Category
                  Status