wikimedia/mediawiki-core

View on GitHub
includes/parser/ParserOptions.php

Summary

Maintainability
F
4 days
Test Coverage

ParserOptions has 107 functions (exceeds 20 allowed). Consider refactoring.
Open

class ParserOptions {

    /**
     * Default values for all options that are relevant for caching.
     * @see self::getDefaults()
Severity: Major
Found in includes/parser/ParserOptions.php - About 2 days to fix

    File ParserOptions.php has 635 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /**
     * Options for the PHP parser
     *
     * This program is free software; you can redistribute it and/or modify
    Severity: Major
    Found in includes/parser/ParserOptions.php - About 1 day to fix

      Method getDefaults has 71 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static function getDefaults() {
              $services = MediaWikiServices::getInstance();
              $mainConfig = $services->getMainConfig();
              $interwikiMagic = $mainConfig->get( MainConfigNames::InterwikiMagic );
              $allowExternalImages = $mainConfig->get( MainConfigNames::AllowExternalImages );
      Severity: Major
      Found in includes/parser/ParserOptions.php - About 2 hrs to fix

        Function matches has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            public function matches( ParserOptions $other ) {
                // Compare most options
                $options = array_keys( $this->options );
                $options = array_diff( $options, [
                    'enableLimitReport', // only affects HTML comments
        Severity: Minor
        Found in includes/parser/ParserOptions.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 optionsHash has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function optionsHash( $forOptions, $title = null ) {
                $renderHashAppend = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::RenderHashAppend );
        
                $inCacheKey = self::allCacheVaryingOptions();
        
        
        Severity: Minor
        Found in includes/parser/ParserOptions.php - About 1 hr to fix

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

              public function setupFakeRevision( $title, $content, $user ) {
                  $oldCallback = $this->setCurrentRevisionRecordCallback(
                      static function (
                          $titleToCheck, $parser = null ) use ( $title, $content, $user, &$oldCallback
                      ) {
          Severity: Minor
          Found in includes/parser/ParserOptions.php - About 1 hr to fix

            Method matches has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function matches( ParserOptions $other ) {
                    // Compare most options
                    $options = array_keys( $this->options );
                    $options = array_diff( $options, [
                        'enableLimitReport', // only affects HTML comments
            Severity: Minor
            Found in includes/parser/ParserOptions.php - About 1 hr to fix

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

                  public function isSafeToCache( array $usedOptions = null ) {
                      $defaults = self::getDefaults();
                      $inCacheKey = self::getCacheVaryingOptionsHash();
                      $usedOptions ??= array_keys( $this->options );
                      foreach ( $usedOptions as $option ) {
              Severity: Minor
              Found in includes/parser/ParserOptions.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 (string)$value;
              Severity: Major
              Found in includes/parser/ParserOptions.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return '[' . implode( ',', array_map( [ $this, 'optionToString' ], $value ) ) . ']';
                Severity: Major
                Found in includes/parser/ParserOptions.php - About 30 mins to fix

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

                      private function optionToString( $value ) {
                          if ( $value === true ) {
                              return '1';
                          } elseif ( $value === false ) {
                              return '0';
                  Severity: Minor
                  Found in includes/parser/ParserOptions.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