MPOS/php-mpos

View on GitHub
include/lib/Mobile_Detect.php

Summary

Maintainability
F
5 days
Test Coverage

Consider simplifying this complex logical expression.
Open

        if (
            // Apple iOS 3.2-5.1 - Tested on the original iPad (4.3 / 5.0), iPad 2 (4.3), iPad 3 (5.1), original iPhone (3.1), iPhone 3 (3.2), 3GS (4.3), 4 (4.3 / 5.0), and 4S (5.1)
            $this->isIOS() && $this->version('iPad', self::VERSION_TYPE_FLOAT)>=4.3 ||
            $this->isIOS() && $this->version('iPhone', self::VERSION_TYPE_FLOAT)>=3.1 ||
            $this->isIOS() && $this->version('iPod', self::VERSION_TYPE_FLOAT)>=3.1 ||
Severity: Critical
Found in include/lib/Mobile_Detect.php - About 1 day to fix

    File Mobile_Detect.php has 561 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /**
     * Mobile Detect Library
     * =====================
     *
    Severity: Major
    Found in include/lib/Mobile_Detect.php - About 1 day to fix

      Function mobileGrade has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
      Open

          public function mobileGrade()
          {
              $isMobile = $this->isMobile();
      
              if (
      Severity: Minor
      Found in include/lib/Mobile_Detect.php - About 7 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

      Consider simplifying this complex logical expression.
      Open

              if (
                  $this->isIOS() && $this->version('iPad', self::VERSION_TYPE_FLOAT)<4.3 ||
                  $this->isIOS() && $this->version('iPhone', self::VERSION_TYPE_FLOAT)<3.1 ||
                  $this->isIOS() && $this->version('iPod', self::VERSION_TYPE_FLOAT)<3.1 ||
      
      
      Severity: Critical
      Found in include/lib/Mobile_Detect.php - About 4 hrs to fix

        Mobile_Detect has 31 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class Mobile_Detect
        {
            /**
             * Mobile detection type.
             *
        Severity: Minor
        Found in include/lib/Mobile_Detect.php - About 3 hrs to fix

          Function checkHttpHeadersForMobile has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              public function checkHttpHeadersForMobile()
              {
          
                  foreach($this->getMobileHeaders() as $mobileHeader => $matchType){
                      if( isset($this->httpHeaders[$mobileHeader]) ){
          Severity: Minor
          Found in include/lib/Mobile_Detect.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

          Method mobileGrade has 49 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function mobileGrade()
              {
                  $isMobile = $this->isMobile();
          
                  if (
          Severity: Minor
          Found in include/lib/Mobile_Detect.php - About 1 hr to fix

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

                public function version($propertyName, $type = self::VERSION_TYPE_STRING)
                {
                    if (empty($propertyName)) {
                        return false;
                    }
            Severity: Minor
            Found in include/lib/Mobile_Detect.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 setUserAgent has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function setUserAgent($userAgent = null)
                {
                    if (!empty($userAgent)) {
                        return $this->userAgent = $userAgent;
                    } else {
            Severity: Minor
            Found in include/lib/Mobile_Detect.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 matchDetectionRulesAgainstUA has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function matchDetectionRulesAgainstUA($userAgent = null)
                {
                    // Begin general search.
                    foreach ($this->getRules() as $_regex) {
                        if (empty($_regex)) {
            Severity: Minor
            Found in include/lib/Mobile_Detect.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