wikimedia/mediawiki-core

View on GitHub
includes/ResourceLoader/WikiModule.php

Summary

Maintainability
F
3 days
Test Coverage

File WikiModule.php has 402 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: Minor
Found in includes/ResourceLoader/WikiModule.php - About 5 hrs to fix

    Function preloadTitleInfo has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function preloadTitleInfo(
            Context $context, array $moduleNames
        ) {
            $rl = $context->getResourceLoader();
            // getDB() can be overridden to point to a foreign database.
    Severity: Minor
    Found in includes/ResourceLoader/WikiModule.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

    WikiModule has 23 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class WikiModule extends Module {
        /** @var string Origin defaults to users with sitewide authority */
        protected $origin = self::ORIGIN_USER_SITEWIDE;
    
        /**
    Severity: Minor
    Found in includes/ResourceLoader/WikiModule.php - About 2 hrs to fix

      Method preloadTitleInfo has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function preloadTitleInfo(
              Context $context, array $moduleNames
          ) {
              $rl = $context->getResourceLoader();
              // getDB() can be overridden to point to a foreign database.
      Severity: Major
      Found in includes/ResourceLoader/WikiModule.php - About 2 hrs to fix

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

            private function getPackageFiles( Context $context ): array {
                $main = null;
        
                $files = [];
                foreach ( $this->getPages( $context ) as $titleText => $options ) {
        Severity: Minor
        Found in includes/ResourceLoader/WikiModule.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 getContentObj has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function getContentObj(
                PageIdentity $page, Context $context, $maxRedirects = 1
            ) {
                $overrideCallback = $context->getContentOverrideCallback();
                $content = $overrideCallback ? call_user_func( $overrideCallback, $page ) : null;
        Severity: Minor
        Found in includes/ResourceLoader/WikiModule.php - About 1 hr to fix

          Method getPackageFiles has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function getPackageFiles( Context $context ): array {
                  $main = null;
          
                  $files = [];
                  foreach ( $this->getPages( $context ) as $titleText => $options ) {
          Severity: Minor
          Found in includes/ResourceLoader/WikiModule.php - About 1 hr to fix

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

                protected function getContentObj(
                    PageIdentity $page, Context $context, $maxRedirects = 1
                ) {
                    $overrideCallback = $context->getContentOverrideCallback();
                    $content = $overrideCallback ? call_user_func( $overrideCallback, $page ) : null;
            Severity: Minor
            Found in includes/ResourceLoader/WikiModule.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 11 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getScript( Context $context ) {
                    if ( $this->isPackaged() ) {
                        return $this->getPackageFiles( $context );
                    } else {
                        $scripts = '';
            Severity: Minor
            Found in includes/ResourceLoader/WikiModule.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 getStyles has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getStyles( Context $context ) {
                    $remoteDir = $this->getConfig()->get( MainConfigNames::ScriptPath );
                    if ( $remoteDir === '' ) {
                        // When the site is configured with the script path at the
                        // document root, MediaWiki uses an empty string but that is
            Severity: Minor
            Found in includes/ResourceLoader/WikiModule.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 invalidateModuleCache has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                public static function invalidateModuleCache(
                    PageIdentity $page,
                    ?RevisionRecord $old,
                    ?RevisionRecord $new,
                    string $domain
            Severity: Minor
            Found in includes/ResourceLoader/WikiModule.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 getPages has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function getPages( Context $context ) {
                    $config = $this->getConfig();
                    $pages = [];
            
                    // Filter out pages from origins not allowed by the current wiki configuration.
            Severity: Minor
            Found in includes/ResourceLoader/WikiModule.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 shouldEmbedModule has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                public function shouldEmbedModule( Context $context ) {
                    $overrideCallback = $context->getContentOverrideCallback();
                    if ( $overrideCallback && $this->getSource() === 'local' ) {
                        foreach ( $this->getPages( $context ) as $page => $info ) {
                            $title = Title::newFromText( $page );
            Severity: Minor
            Found in includes/ResourceLoader/WikiModule.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 getTitleInfo has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function getTitleInfo( Context $context ) {
                    $pageNames = array_keys( $this->getPages( $context ) );
                    sort( $pageNames );
                    $batchKey = implode( '|', $pageNames );
                    if ( !isset( $this->titleInfo[$batchKey] ) ) {
            Severity: Minor
            Found in includes/ResourceLoader/WikiModule.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 isKnownEmpty has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function isKnownEmpty( Context $context ) {
                    // If a module has dependencies it cannot be empty. An empty array will be cast to false
                    if ( $this->getDependencies() ) {
                        return false;
                    }
            Severity: Minor
            Found in includes/ResourceLoader/WikiModule.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 $content;
            Severity: Major
            Found in includes/ResourceLoader/WikiModule.php - About 30 mins to fix

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

                  protected function getContent( $titleText, Context $context ) {
                      $pageStore = MediaWikiServices::getInstance()->getPageStore();
                      $title = $pageStore->getPageByText( $titleText );
                      if ( !$title ) {
                          return null; // Bad title
              Severity: Minor
              Found in includes/ResourceLoader/WikiModule.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 fetchTitleInfo has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected static function fetchTitleInfo( IReadableDatabase $db, array $pages, $fname = __METHOD__ ) {
                      $titleInfo = [];
                      $linkBatchFactory = MediaWikiServices::getInstance()->getLinkBatchFactory();
                      $batch = $linkBatchFactory->newLinkBatch();
                      foreach ( $pages as $titleText ) {
              Severity: Minor
              Found in includes/ResourceLoader/WikiModule.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