wikimedia/mediawiki-extensions-MobileFrontend

View on GitHub
includes/MobileContext.php

Summary

Maintainability
D
2 days
Test Coverage

File MobileContext.php has 436 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

use MediaWiki\Config\Config;
use MediaWiki\Context\ContextSource;
use MediaWiki\Context\IContextSource;
Severity: Minor
Found in includes/MobileContext.php - About 6 hrs to fix

    MobileContext has 41 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class MobileContext extends ContextSource {
        public const MODE_BETA = 'beta';
        public const MODE_STABLE = 'stable';
        public const OPTIN_COOKIE_NAME = 'optin';
        public const STOP_MOBILE_REDIRECT_COOKIE_NAME = 'stopMobileRedirect';
    Severity: Minor
    Found in includes/MobileContext.php - About 5 hrs to fix

      Function getMobileMode has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          private function getMobileMode() {
              $enableBeta = $this->config->get( 'MFEnableBeta' );
      
              if ( !$enableBeta ) {
                  return '';
      Severity: Minor
      Found in includes/MobileContext.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 doToggling has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          public function doToggling() {
              // make sure viewChange is set
              $this->shouldDisplayMobileView();
      
              if ( !$this->viewChange ) {
      Severity: Minor
      Found in includes/MobileContext.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 doToggling has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function doToggling() {
              // make sure viewChange is set
              $this->shouldDisplayMobileView();
      
              if ( !$this->viewChange ) {
      Severity: Minor
      Found in includes/MobileContext.php - About 1 hr to fix

        Method shouldDisplayMobileViewInternal has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function shouldDisplayMobileViewInternal() {
                // May be overridden programmatically
                if ( $this->forceMobileView ) {
                    return true;
                }
        Severity: Minor
        Found in includes/MobileContext.php - About 1 hr to fix

          Function getMobileUrl has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getMobileUrl( $url, $forceHttps = false ) {
                  $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
                  $parsedUrl = $urlUtils->parse( $url );
                  // if parsing failed, maybe it's a local Url, try to expand and reparse it - task T107505
                  if ( !$parsedUrl ) {
          Severity: Minor
          Found in includes/MobileContext.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 shouldDisplayMobileViewInternal has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              private function shouldDisplayMobileViewInternal() {
                  // May be overridden programmatically
                  if ( $this->forceMobileView ) {
                      return true;
                  }
          Severity: Minor
          Found in includes/MobileContext.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 true;
          Severity: Major
          Found in includes/MobileContext.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return false;
            Severity: Major
            Found in includes/MobileContext.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return true;
              Severity: Major
              Found in includes/MobileContext.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return false;
                Severity: Major
                Found in includes/MobileContext.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return true;
                  Severity: Major
                  Found in includes/MobileContext.php - About 30 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status