wikimedia/mediawiki-extensions-UniversalLanguageSelector

View on GitHub
includes/Hooks.php

Summary

Maintainability
C
1 day
Test Coverage

File Hooks.php has 351 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Hooks for UniversalLanguageSelector extension.
 *
 * Copyright (C) 2012-2018 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon
Severity: Minor
Found in includes/Hooks.php - About 4 hrs to fix

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

        public function onBeforePageDisplay( $out, $skin ): void {
            $unsupportedSkins = [ 'minerva', 'apioutput' ];
            if ( in_array( $skin->getSkinName(), $unsupportedSkins, true ) ) {
                return;
            }
    Severity: Minor
    Found in includes/Hooks.php - About 1 hr to fix

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

          public function onUserGetLanguageObject( $user, &$code, $context ) {
              if ( $this->config->get( 'ULSLanguageDetection' ) ) {
                  // Vary any caching based on the header value. Note that
                  // we need to vary regardless of whether we end up using
                  // the header or not, so that requests without the header
      Severity: Minor
      Found in includes/Hooks.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 onUserGetLanguageObject has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function onUserGetLanguageObject( $user, &$code, $context ) {
              if ( $this->config->get( 'ULSLanguageDetection' ) ) {
                  // Vary any caching based on the header value. Note that
                  // we need to vary regardless of whether we end up using
                  // the header or not, so that requests without the header
      Severity: Minor
      Found in includes/Hooks.php - About 1 hr to fix

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

            public function onBeforePageDisplay( $out, $skin ): void {
                $unsupportedSkins = [ 'minerva', 'apioutput' ];
                if ( in_array( $skin->getSkinName(), $unsupportedSkins, true ) ) {
                    return;
                }
        Severity: Minor
        Found in includes/Hooks.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 onSkinAfterPortlet has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            public function onSkinAfterPortlet( $skin, $name, &$content ) {
                if ( $name !== 'lang' ) {
                    return;
                }
        
        
        Severity: Minor
        Found in includes/Hooks.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 false;
        Severity: Major
        Found in includes/Hooks.php - About 30 mins to fix

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

              protected function getDefaultLanguage( array $preferred ) {
                  /** @var array supported List of Supported languages by MediaWiki internal language codes */
                  $supported = $this->languageNameUtils
                      ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED );
          
          
          Severity: Minor
          Found in includes/Hooks.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