railpage/railpagecore

View on GitHub
lib/GTFS/AU/VIC/PTV/PTV.php

Summary

Maintainability
D
2 days
Test Coverage

Function StopsNearLocation has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    public function StopsNearLocation($latitude = null, $longitude = null) {
        if ($latitude == null) {
            throw new Exception("Cannot fetch " . __METHOD__ . " - no latitude given");
        }
        
Severity: Minor
Found in lib/GTFS/AU/VIC/PTV/PTV.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

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

    public function fetch($method = null, $parameters = array(), $other = array()) {
        if ($method == null && empty($parameters)) {
            throw new Exception("Cannot fetch API query - no API method defined");
        }
        
Severity: Minor
Found in lib/GTFS/AU/VIC/PTV/PTV.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 fetch has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function fetch($method = null, $parameters = array(), $other = array()) {
        if ($method == null && empty($parameters)) {
            throw new Exception("Cannot fetch API query - no API method defined");
        }
        
Severity: Minor
Found in lib/GTFS/AU/VIC/PTV/PTV.php - About 1 hr to fix

    Method StopsNearLocation has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function StopsNearLocation($latitude = null, $longitude = null) {
            if ($latitude == null) {
                throw new Exception("Cannot fetch " . __METHOD__ . " - no latitude given");
            }
            
    Severity: Minor
    Found in lib/GTFS/AU/VIC/PTV/PTV.php - About 1 hr to fix

      The method fetch() has an NPath complexity of 1152. The configured NPath complexity threshold is 200.
      Open

          public function fetch($method = null, $parameters = array(), $other = array()) {
              if ($method == null && empty($parameters)) {
                  throw new Exception("Cannot fetch API query - no API method defined");
              }
              
      Severity: Minor
      Found in lib/GTFS/AU/VIC/PTV/PTV.php by phpmd

      NPathComplexity

      Since: 0.1

      The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

      Example

      class Foo {
          function bar() {
              // lots of complicated code
          }
      }

      Source https://phpmd.org/rules/codesize.html#npathcomplexity

      The method getRoutes() has 133 lines of code. Current threshold is set to 100. Avoid really long methods.
      Open

          public function getRoutes() {
              
              $params = array("line");
              
              $results = $this->fetch("search", $params);
      Severity: Minor
      Found in lib/GTFS/AU/VIC/PTV/PTV.php by phpmd

      The method StopsNearLocation() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
      Open

          public function StopsNearLocation($latitude = null, $longitude = null) {
              if ($latitude == null) {
                  throw new Exception("Cannot fetch " . __METHOD__ . " - no latitude given");
              }
              
      Severity: Minor
      Found in lib/GTFS/AU/VIC/PTV/PTV.php by phpmd

      CyclomaticComplexity

      Since: 0.1

      Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

      Example

      // Cyclomatic Complexity = 11
      class Foo {
      1   public function example() {
      2       if ($a == $b) {
      3           if ($a1 == $b1) {
                      fiddle();
      4           } elseif ($a2 == $b2) {
                      fiddle();
                  } else {
                      fiddle();
                  }
      5       } elseif ($c == $d) {
      6           while ($c == $d) {
                      fiddle();
                  }
      7        } elseif ($e == $f) {
      8           for ($n = 0; $n < $h; $n++) {
                      fiddle();
                  }
              } else {
                  switch ($z) {
      9               case 1:
                          fiddle();
                          break;
      10              case 2:
                          fiddle();
                          break;
      11              case 3:
                          fiddle();
                          break;
                      default:
                          fiddle();
                          break;
                  }
              }
          }
      }

      Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

      The method fetch() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
      Open

          public function fetch($method = null, $parameters = array(), $other = array()) {
              if ($method == null && empty($parameters)) {
                  throw new Exception("Cannot fetch API query - no API method defined");
              }
              
      Severity: Minor
      Found in lib/GTFS/AU/VIC/PTV/PTV.php by phpmd

      CyclomaticComplexity

      Since: 0.1

      Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

      Example

      // Cyclomatic Complexity = 11
      class Foo {
      1   public function example() {
      2       if ($a == $b) {
      3           if ($a1 == $b1) {
                      fiddle();
      4           } elseif ($a2 == $b2) {
                      fiddle();
                  } else {
                      fiddle();
                  }
      5       } elseif ($c == $d) {
      6           while ($c == $d) {
                      fiddle();
                  }
      7        } elseif ($e == $f) {
      8           for ($n = 0; $n < $h; $n++) {
                      fiddle();
                  }
              } else {
                  switch ($z) {
      9               case 1:
                          fiddle();
                          break;
      10              case 2:
                          fiddle();
                          break;
      11              case 3:
                          fiddle();
                          break;
                      default:
                          fiddle();
                          break;
                  }
              }
          }
      }

      Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

      The method fetch uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  foreach ($parameters as $key => $val) {
                      if (!is_array($val)) {
                          $url .= "/" . urlencode($key) . "/" . urlencode($val); 
                      }
      Severity: Minor
      Found in lib/GTFS/AU/VIC/PTV/PTV.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

      Source https://phpmd.org/rules/cleancode.html#elseexpression

      Identical blocks of code found in 3 locations. Consider refactoring.
      Open

              $this->adapter = new Adapter(array(
                  "driver" => "Mysqli",
                  "database" => $this->Config->GTFS->PTV->db_name,
                  "username" => $this->Config->GTFS->PTV->db_user,
                  "password" => $this->Config->GTFS->PTV->db_pass,
      Severity: Major
      Found in lib/GTFS/AU/VIC/PTV/PTV.php and 2 other locations - About 3 hrs to fix
      lib/GTFS/StandardProvider.php on lines 66..72
      lib/GTFS/StandardRoute.php on lines 50..56

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 74.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          public $ignore_routes = array(
              "Yarram - Melbourne via Koo Wee Rup & Dandenong",
              "Warrnambool - Melbourne via Colac & Geelong",
              "Warrnambool - Melbourne via Apollo Bay & Geelong",
              "Canberra - Melbourne via Bairnsdale",
      Severity: Major
      Found in lib/GTFS/AU/VIC/PTV/PTV.php and 1 other location - About 1 hr to fix
      lib/Formatting/EmoticonsUtility.php on lines 127..127

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 35.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

              if (count($data)) {
                  $url .= "?" . implode("&", $data); 
              }
      Severity: Major
      Found in lib/GTFS/AU/VIC/PTV/PTV.php and 3 other locations - About 1 hr to fix
      lib/Images/Utility/Geoplace.php on lines 92..94
      lib/Jobs/Jobs.php on lines 100..102
      lib/Locations/Locations.php on lines 243..245

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 33.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 5 locations. Consider refactoring.
      Open

              $config = array(
                  'adapter' => 'Zend\Http\Client\Adapter\Curl',
                  'curloptions' => array(CURLOPT_FOLLOWLOCATION => true),
              );
      Severity: Major
      Found in lib/GTFS/AU/VIC/PTV/PTV.php and 4 other locations - About 1 hr to fix
      lib/Bugs/Bugs.php on lines 51..54
      lib/Graphite/Graph.php on lines 87..90
      lib/Jobs/Scraper.php on lines 202..205
      lib/News/Scraper.php on lines 137..140

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 30.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

              if ($longitude == null) {
                  throw new Exception("Cannot fetch " . __METHOD__ . " - no longitude given");
              }
      Severity: Major
      Found in lib/GTFS/AU/VIC/PTV/PTV.php and 3 other locations - About 1 hr to fix
      lib/GTFS/AU/VIC/PTV/PTV.php on lines 307..309
      lib/GTFS/StandardProvider.php on lines 106..108
      lib/GTFS/StandardProvider.php on lines 110..112

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 30.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

              if ($latitude == null) {
                  throw new Exception("Cannot fetch " . __METHOD__ . " - no latitude given");
              }
      Severity: Major
      Found in lib/GTFS/AU/VIC/PTV/PTV.php and 3 other locations - About 1 hr to fix
      lib/GTFS/AU/VIC/PTV/PTV.php on lines 311..313
      lib/GTFS/StandardProvider.php on lines 106..108
      lib/GTFS/StandardProvider.php on lines 110..112

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 30.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

                  $row['result']['location_name'] = trim($row['result']['location_name']);
      Severity: Major
      Found in lib/GTFS/AU/VIC/PTV/PTV.php and 2 other locations - About 1 hr to fix
      lib/Railcams/Camera.php on lines 654..654
      lib/Railcams/Camera.php on lines 740..740

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 30.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 3 locations. Consider refactoring.
      Open

              if (function_exists("getRailpageConfig")) {
                  $this->Config = getRailpageConfig();
              }
      Severity: Major
      Found in lib/GTFS/AU/VIC/PTV/PTV.php and 2 other locations - About 45 mins to fix
      lib/GTFS/StandardRoute.php on lines 46..48
      lib/Graphite/Graph.php on lines 69..71

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 25.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 7 locations. Consider refactoring.
      Open

                          $result = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE); 
      Severity: Major
      Found in lib/GTFS/AU/VIC/PTV/PTV.php and 6 other locations - About 30 mins to fix
      lib/GTFS/StandardProvider.php on lines 136..136
      lib/GTFS/StandardProvider.php on lines 180..180
      lib/GTFS/StandardRoute.php on lines 74..74
      lib/GTFS/StandardRoute.php on lines 103..103
      lib/GTFS/StandardRoute.php on lines 141..141
      lib/GTFS/StandardRoute.php on lines 160..160

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 21.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

                          !preg_match("@#([0-9]{0,3})@", $row['result']['location_name'])
      Severity: Major
      Found in lib/GTFS/AU/VIC/PTV/PTV.php and 3 other locations - About 30 mins to fix
      lib/Formatting/BbcodeEtc/Filters/ImageFilter.php on lines 61..61
      lib/Jobs/Scraper.php on lines 112..112
      lib/News/News.php on lines 149..149

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 20.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      There are no issues that match your filters.

      Category
      Status