wikimedia/mediawiki-core

View on GitHub
includes/registration/ExtensionProcessor.php

Summary

Maintainability
F
6 days
Test Coverage

File ExtensionProcessor.php has 677 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

use MediaWiki\MainConfigNames;
use MediaWiki\ResourceLoader\FilePath;

Severity: Major
Found in includes/registration/ExtensionProcessor.php - About 1 day to fix

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

        protected function extractResourceLoaderModules( $dir, array $info ) {
            $defaultPaths = $info['ResourceFileModulePaths'] ?? false;
            if ( isset( $defaultPaths['localBasePath'] ) ) {
                if ( $defaultPaths['localBasePath'] === '' ) {
                    // Avoid double slashes (e.g. /extensions/Example//path)
    Severity: Minor
    Found in includes/registration/ExtensionProcessor.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

    Function extractNamespaces has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function extractNamespaces( array $info ) {
            if ( isset( $info['namespaces'] ) ) {
                foreach ( $info['namespaces'] as $ns ) {
                    if ( defined( $ns['constant'] ) ) {
                        // If the namespace constant is already defined, use it.
    Severity: Minor
    Found in includes/registration/ExtensionProcessor.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

    Function extractInfo has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        public function extractInfo( $path, array $info, $version ) {
            $dir = dirname( $path );
            $this->extractHooks( $info, $path );
            $this->extractExtensionMessagesFiles( $dir, $info );
            $this->extractMessagesDirs( $dir, $info );
    Severity: Minor
    Found in includes/registration/ExtensionProcessor.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

    ExtensionProcessor has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ExtensionProcessor implements Processor {
    
        /**
         * Keys that should be set to $GLOBALS
         *
    Severity: Minor
    Found in includes/registration/ExtensionProcessor.php - About 3 hrs to fix

      Function extractConfig2 has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function extractConfig2( array $info, $dir ) {
              $prefix = $info['config_prefix'] ?? 'wg';
              if ( isset( $info['config'] ) ) {
                  foreach ( $info['config'] as $key => $data ) {
                      if ( !array_key_exists( 'value', $data ) ) {
      Severity: Minor
      Found in includes/registration/ExtensionProcessor.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 extractInfo has 62 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function extractInfo( $path, array $info, $version ) {
              $dir = dirname( $path );
              $this->extractHooks( $info, $path );
              $this->extractExtensionMessagesFiles( $dir, $info );
              $this->extractMessagesDirs( $dir, $info );
      Severity: Major
      Found in includes/registration/ExtensionProcessor.php - About 2 hrs to fix

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

            public function getRequirements( array $info, $includeDev ) {
                // Quick shortcuts
                if ( !$includeDev || !isset( $info['dev-requires'] ) ) {
                    return $info['requires'] ?? [];
                }
        Severity: Minor
        Found in includes/registration/ExtensionProcessor.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 getRequirements has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function getRequirements( array $info, $includeDev ) {
                // Quick shortcuts
                if ( !$includeDev || !isset( $info['dev-requires'] ) ) {
                    return $info['requires'] ?? [];
                }
        Severity: Major
        Found in includes/registration/ExtensionProcessor.php - About 2 hrs to fix

          Method extractResourceLoaderModules has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function extractResourceLoaderModules( $dir, array $info ) {
                  $defaultPaths = $info['ResourceFileModulePaths'] ?? false;
                  if ( isset( $defaultPaths['localBasePath'] ) ) {
                      if ( $defaultPaths['localBasePath'] === '' ) {
                          // Avoid double slashes (e.g. /extensions/Example//path)
          Severity: Minor
          Found in includes/registration/ExtensionProcessor.php - About 1 hr to fix

            Function setArrayHookHandler has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

                private function setArrayHookHandler(
                    array $callback,
                    array $hookHandlersAttr,
                    string $name,
                    string $path
            Severity: Minor
            Found in includes/registration/ExtensionProcessor.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 extractHooks has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function extractHooks( array $info, string $path ) {
                    $extName = $info['name'];
                    if ( isset( $info['Hooks'] ) ) {
                        $hookHandlersAttr = [];
                        foreach ( $info['HookHandlers'] ?? [] as $name => $def ) {
            Severity: Minor
            Found in includes/registration/ExtensionProcessor.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 extractNamespaces has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function extractNamespaces( array $info ) {
                    if ( isset( $info['namespaces'] ) ) {
                        foreach ( $info['namespaces'] as $ns ) {
                            if ( defined( $ns['constant'] ) ) {
                                // If the namespace constant is already defined, use it.
            Severity: Minor
            Found in includes/registration/ExtensionProcessor.php - About 1 hr to fix

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

                  public function getExtractedInfo( bool $includeDev = false ) {
                      // Make sure the merge strategies are set
                      foreach ( $this->globals as $key => $val ) {
                          if ( isset( self::MERGE_STRATEGIES[$key] ) ) {
                              $this->globals[$key][ExtensionRegistry::MERGE_STRATEGY] = self::MERGE_STRATEGIES[$key];
              Severity: Minor
              Found in includes/registration/ExtensionProcessor.php - About 1 hr to fix

                Method extractHooks has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function extractHooks( array $info, string $path ) {
                        $extName = $info['name'];
                        if ( isset( $info['Hooks'] ) ) {
                            $hookHandlersAttr = [];
                            foreach ( $info['HookHandlers'] ?? [] as $name => $def ) {
                Severity: Minor
                Found in includes/registration/ExtensionProcessor.php - About 1 hr to fix

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

                      public function getExtractedInfo( bool $includeDev = false ) {
                          // Make sure the merge strategies are set
                          foreach ( $this->globals as $key => $val ) {
                              if ( isset( self::MERGE_STRATEGIES[$key] ) ) {
                                  $this->globals[$key][ExtensionRegistry::MERGE_STRATEGY] = self::MERGE_STRATEGIES[$key];
                  Severity: Minor
                  Found in includes/registration/ExtensionProcessor.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

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

                      protected function extractConfig1( array $info ) {
                          if ( isset( $info['config'] ) ) {
                              if ( isset( $info['config']['_prefix'] ) ) {
                                  $prefix = $info['config']['_prefix'];
                                  unset( $info['config']['_prefix'] );
                  Severity: Minor
                  Found in includes/registration/ExtensionProcessor.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

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

                      private function extractAutoload( array $info, string $dir ) {
                          if ( isset( $info['load_composer_autoloader'] ) && $info['load_composer_autoloader'] === true ) {
                              $file = "$dir/vendor/autoload.php";
                              if ( file_exists( $file ) ) {
                                  $this->autoload['files'][] = $file;
                  Severity: Minor
                  Found in includes/registration/ExtensionProcessor.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 "$a $b";
                  Severity: Major
                  Found in includes/registration/ExtensionProcessor.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return $merged;
                    Severity: Major
                    Found in includes/registration/ExtensionProcessor.php - About 30 mins to fix

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

                          protected function extractSkins( $dir, array $info ) {
                              if ( isset( $info['ValidSkinNames'] ) ) {
                                  foreach ( $info['ValidSkinNames'] as $skinKey => $data ) {
                                      if ( isset( $data['args'][0] ) ) {
                                          $templateDirectory = $data['args'][0]['templateDirectory'] ?? 'templates';
                      Severity: Minor
                      Found in includes/registration/ExtensionProcessor.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

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

                          protected function extractMessagesDirs( $dir, array $info ) {
                              if ( isset( $info['MessagesDirs'] ) ) {
                                  foreach ( $info['MessagesDirs'] as $name => $files ) {
                                      foreach ( (array)$files as $file ) {
                                          $this->globals["wgMessagesDirs"][$name][] = "$dir/$file";
                      Severity: Minor
                      Found in includes/registration/ExtensionProcessor.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

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                          protected function storeToArrayRecursive( $path, $name, $value, &$array ) {
                              if ( !is_array( $value ) ) {
                                  throw new InvalidArgumentException( "The value for '$name' should be an array (from $path)" );
                              }
                              if ( isset( $array[$name] ) ) {
                      Severity: Minor
                      Found in includes/registration/ExtensionProcessor.php and 1 other location - About 1 hr to fix
                      includes/registration/ExtensionProcessor.php on lines 942..951

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 100.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                          protected function storeToArray( $path, $name, $value, &$array ) {
                              if ( !is_array( $value ) ) {
                                  throw new InvalidArgumentException( "The value for '$name' should be an array (from $path)" );
                              }
                              if ( isset( $array[$name] ) ) {
                      Severity: Minor
                      Found in includes/registration/ExtensionProcessor.php and 1 other location - About 1 hr to fix
                      includes/registration/ExtensionProcessor.php on lines 922..931

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 100.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      There are no issues that match your filters.

                      Category
                      Status