wikimedia/mediawiki-core

View on GitHub
includes/ResourceLoader/FileModule.php

Summary

Maintainability
F
1 wk
Test Coverage

File FileModule.php has 858 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/ResourceLoader/FileModule.php - About 2 days to fix

    FileModule has 46 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class FileModule extends Module {
        /** @var string Local base path, see __construct() */
        protected $localBasePath = '';
    
        /** @var string Remote base path, see __construct() */
    Severity: Minor
    Found in includes/ResourceLoader/FileModule.php - About 6 hrs to fix

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

          private function expandFileInfo( Context $context, $fileInfo, $debugKey ) {
              if ( is_string( $fileInfo ) ) {
                  // Inline common case
                  return [
                      'name' => $fileInfo,
      Severity: Minor
      Found in includes/ResourceLoader/FileModule.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 __construct has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
      Open

          public function __construct(
              array $options = [],
              string $localBasePath = null,
              string $remoteBasePath = null
          ) {
      Severity: Minor
      Found in includes/ResourceLoader/FileModule.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

      Method expandFileInfo has 97 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function expandFileInfo( Context $context, $fileInfo, $debugKey ) {
              if ( is_string( $fileInfo ) ) {
                  // Inline common case
                  return [
                      'name' => $fileInfo,
      Severity: Major
      Found in includes/ResourceLoader/FileModule.php - About 3 hrs to fix

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

            public function __construct(
                array $options = [],
                string $localBasePath = null,
                string $remoteBasePath = null
            ) {
        Severity: Major
        Found in includes/ResourceLoader/FileModule.php - About 2 hrs to fix

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

              private function expandPackageFiles( Context $context ) {
                  $hash = $context->getHash();
                  if ( isset( $this->expandedPackageFiles[$hash] ) ) {
                      return $this->expandedPackageFiles[$hash];
                  }
          Severity: Minor
          Found in includes/ResourceLoader/FileModule.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 readFileInfo has 55 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function readFileInfo( Context $context, array &$fileInfo ) {
                  // Turn any 'filePath' or 'callback' key into actual 'content',
                  // and remove the key after that. The callback could return a
                  // FilePath object; if that happens, fall through to the 'filePath'
                  // handling.
          Severity: Major
          Found in includes/ResourceLoader/FileModule.php - About 2 hrs to fix

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

                private function readFileInfo( Context $context, array &$fileInfo ) {
                    // Turn any 'filePath' or 'callback' key into actual 'content',
                    // and remove the key after that. The callback could return a
                    // FilePath object; if that happens, fall through to the 'filePath'
                    // handling.
            Severity: Minor
            Found in includes/ResourceLoader/FileModule.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 getFileHashes has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

                private function getFileHashes( Context $context ) {
                    $files = [];
            
                    foreach ( $this->getStyleFiles( $context ) as $filePaths ) {
                        foreach ( $filePaths as $filePath ) {
            Severity: Minor
            Found in includes/ResourceLoader/FileModule.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 compileLessString has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function compileLessString( $style, $stylePath, Context $context ) {
                    static $cache;
                    // @TODO: dependency injection
                    if ( !$cache ) {
                        $cache = MediaWikiServices::getInstance()->getObjectCacheFactory()
            Severity: Minor
            Found in includes/ResourceLoader/FileModule.php - About 1 hr to fix

              Method expandPackageFiles has 39 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function expandPackageFiles( Context $context ) {
                      $hash = $context->getHash();
                      if ( isset( $this->expandedPackageFiles[$hash] ) ) {
                          return $this->expandedPackageFiles[$hash];
                      }
              Severity: Minor
              Found in includes/ResourceLoader/FileModule.php - About 1 hr to fix

                Method getDefinitionSummary has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function getDefinitionSummary( Context $context ) {
                        $summary = parent::getDefinitionSummary( $context );
                
                        $options = [];
                        foreach ( [
                Severity: Minor
                Found in includes/ResourceLoader/FileModule.php - About 1 hr to fix

                  Method getFileHashes has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function getFileHashes( Context $context ) {
                          $files = [];
                  
                          foreach ( $this->getStyleFiles( $context ) as $filePaths ) {
                              foreach ( $filePaths as $filePath ) {
                  Severity: Minor
                  Found in includes/ResourceLoader/FileModule.php - About 1 hr to fix

                    Function hasGeneratedScripts has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function hasGeneratedScripts() {
                            foreach (
                                [ $this->scripts, $this->languageScripts, $this->skinScripts, $this->debugScripts ]
                                as $scripts
                            ) {
                    Severity: Minor
                    Found in includes/ResourceLoader/FileModule.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 setSkinStylesOverride has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function setSkinStylesOverride( array $moduleSkinStyles ): void {
                            $moduleName = $this->getName();
                            foreach ( $moduleSkinStyles as $skinName => $overrides ) {
                                // If a module provides overrides for a skin, and that skin also provides overrides
                                // for the same module, then the module has precedence.
                    Severity: Minor
                    Found in includes/ResourceLoader/FileModule.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 getScript has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function getScript( Context $context ) {
                            $packageFiles = $this->getPackageFiles( $context );
                            if ( $packageFiles !== null ) {
                                foreach ( $packageFiles['files'] as &$file ) {
                                    if ( $file['type'] === 'script+style' ) {
                    Severity: Minor
                    Found in includes/ResourceLoader/FileModule.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 getLanguageScripts has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function getLanguageScripts( string $lang ): array {
                            $scripts = self::tryForKey( $this->languageScripts, $lang );
                            if ( $scripts ) {
                                return $scripts;
                            }
                    Severity: Minor
                    Found in includes/ResourceLoader/FileModule.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 processStyle has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected function processStyle( $style, $styleLang, $path, Context $context ) {
                            $localPath = $this->getLocalPath( $path );
                            $remotePath = $this->getRemotePath( $path );
                    
                            if ( $styleLang === 'less' ) {
                    Severity: Minor
                    Found in includes/ResourceLoader/FileModule.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 getStyles has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function getStyles( Context $context ) {
                            $styles = $this->readStyleFiles(
                                $this->getStyleFiles( $context ),
                                $context
                            );
                    Severity: Minor
                    Found in includes/ResourceLoader/FileModule.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 getDefinitionSummary has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function getDefinitionSummary( Context $context ) {
                            $summary = parent::getDefinitionSummary( $context );
                    
                            $options = [];
                            foreach ( [
                    Severity: Minor
                    Found in includes/ResourceLoader/FileModule.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 extractBasePaths has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function extractBasePaths(
                            array $options = [],
                            $localBasePath = null,
                            $remoteBasePath = null
                        ) {
                    Severity: Minor
                    Found in includes/ResourceLoader/FileModule.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