wikimedia/mediawiki-core

View on GitHub
maintenance/includes/MaintenanceRunner.php

Summary

Maintainability
D
2 days
Test Coverage

File MaintenanceRunner.php has 457 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace MediaWiki\Maintenance;

use Exception;
Severity: Minor
Found in maintenance/includes/MaintenanceRunner.php - About 7 hrs to fix

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

    class MaintenanceRunner {
    
        /**
         * Identifies the script to execute. This may be a class name, the relative or absolute
         * path of a script file, a plain name with or without an extension prefix, etc.
    Severity: Minor
    Found in maintenance/includes/MaintenanceRunner.php - About 3 hrs to fix

      Method run has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function run(): bool {
              $config = $this->getConfig();
      
              // Apply warning thresholds and output mode to Profiler.
              // This MUST happen after Setup.php calls MaintenanceRunner::setup,
      Severity: Minor
      Found in maintenance/includes/MaintenanceRunner.php - About 1 hr to fix

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

            public function initFromWrapper( array $argv ) {
                $script = null;
        
                $this->parameters->setName( $argv[0] );
                $this->parameters->setAllowUnregisteredOptions( true );
        Severity: Minor
        Found in maintenance/includes/MaintenanceRunner.php - About 1 hr to fix

          Method setup has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function setup( SettingsBuilder $settings ) {
                  // NOTE: this has to happen after the autoloader has been initialized.
                  $scriptClass = $this->getScriptClass();
          
                  $cls = new ReflectionClass( $scriptClass );
          Severity: Minor
          Found in maintenance/includes/MaintenanceRunner.php - About 1 hr to fix

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

                public function defineSettings() {
                    global $IP;
            
                    if ( $this->parameters->hasOption( 'conf' ) ) {
                        // Define the constant instead of directly setting $settingsFile
            Severity: Minor
            Found in maintenance/includes/MaintenanceRunner.php - About 1 hr to fix

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

                  public function defineSettings() {
                      global $IP;
              
                      if ( $this->parameters->hasOption( 'conf' ) ) {
                          // Define the constant instead of directly setting $settingsFile
              Severity: Minor
              Found in maintenance/includes/MaintenanceRunner.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 overrideConfig has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function overrideConfig( SettingsBuilder $settingsBuilder ) {
                      $config = $settingsBuilder->getConfig();
              
                      if ( $this->scriptObject->getDbType() === Maintenance::DB_NONE ) {
                          $cacheConf = $config->get( MainConfigNames::LocalisationCacheConf );
              Severity: Minor
              Found in maintenance/includes/MaintenanceRunner.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 initFromWrapper has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function initFromWrapper( array $argv ) {
                      $script = null;
              
                      $this->parameters->setName( $argv[0] );
                      $this->parameters->setAllowUnregisteredOptions( true );
              Severity: Minor
              Found in maintenance/includes/MaintenanceRunner.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 findScriptClass has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function findScriptClass( string $script ): string {
                      [ $extName, $scriptName ] = $this->splitScript( $script );
              
                      if ( $extName !== null ) {
                          $extension = $this->getExtensionInfo( $extName );
              Severity: Minor
              Found in maintenance/includes/MaintenanceRunner.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 run has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function run(): bool {
                      $config = $this->getConfig();
              
                      // Apply warning thresholds and output mode to Profiler.
                      // This MUST happen after Setup.php calls MaintenanceRunner::setup,
              Severity: Minor
              Found in maintenance/includes/MaintenanceRunner.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 shutdown has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function shutdown() {
                      $lbFactory = null;
                      if (
                          $this->scriptObject->getDbType() !== Maintenance::DB_NONE &&
                          // Service might be disabled, e.g. when running install.php
              Severity: Minor
              Found in maintenance/includes/MaintenanceRunner.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 preloadScriptFile has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function preloadScriptFile( string $script ): void {
                      if ( $this->scriptClass !== null && class_exists( $this->scriptClass ) ) {
                          // We know the script class, and file-level code was executed because class_exists triggers auto-loading.
                          return;
                      }
              Severity: Minor
              Found in maintenance/includes/MaintenanceRunner.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 shouldExecute has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function shouldExecute() {
                      if ( !function_exists( 'debug_backtrace' ) ) {
                          // If someone has a better idea...
                          return MW_ENTRY_POINT === 'cli';
                      }
              Severity: Minor
              Found in maintenance/includes/MaintenanceRunner.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 isAbsolutePath has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  private static function isAbsolutePath( $path ) {
                      if ( str_starts_with( $path, '/' ) ) {
                          return true;
                      }
              
              
              Severity: Minor
              Found in maintenance/includes/MaintenanceRunner.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 expandScriptFile has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function expandScriptFile( string $scriptName, ?array $extension ): string {
                      // Append ".php" if not present
                      $scriptFile = $scriptName;
                      if ( !str_ends_with( $scriptFile, '.php' ) ) {
                          $scriptFile .= '.php';
              Severity: Minor
              Found in maintenance/includes/MaintenanceRunner.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