railpage/railpagecore

View on GitHub
lib/Locos/Utility/LocomotiveUtility.php

Summary

Maintainability
F
3 days
Test Coverage

The class LocomotiveUtility has an overall complexity of 53 which is very high. The configured complexity threshold is 50.
Open

class LocomotiveUtility {

    /**
     * Fetch locomotive data from Memcached/Redis/Database
     * @since Version 3.9.1

File LocomotiveUtility.php has 253 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * Locomotive utility class
 * @since Version 3.9.1
Severity: Minor
Found in lib/Locos/Utility/LocomotiveUtility.php - About 2 hrs to fix

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

        public static function getDescriptionBits_Dates(Locomotive $Loco, $bits) {
    
            $dates = $Loco->loadDates();
            $dates = array_reverse($dates);
    
    
    Severity: Minor
    Found in lib/Locos/Utility/LocomotiveUtility.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 getSubmitData has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function getSubmitData(Locomotive $Loco) {
    
            // Drop whitespace from loco numbers of all types except steam
            if (in_array($Loco->class_id, array(2, 3, 4, 5, 6)) ||
                    ($Loco->Class instanceof LocoClass && in_array($Loco->Class->type_id, array(2, 3, 4, 5, 6))) ||
    Severity: Minor
    Found in lib/Locos/Utility/LocomotiveUtility.php - About 1 hr to fix

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

          private static function getLocoIDFromClassIDAndLocoNumber($class_id, $loco_num) {
      
              $Memcached = AppCore::getMemcached();
              $Database = (new AppCore)->getDatabaseConnection();
      
      
      Severity: Minor
      Found in lib/Locos/Utility/LocomotiveUtility.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 getSubmitData has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function getSubmitData(Locomotive $Loco) {
      
              // Drop whitespace from loco numbers of all types except steam
              if (in_array($Loco->class_id, array(2, 3, 4, 5, 6)) ||
                      ($Loco->Class instanceof LocoClass && in_array($Loco->Class->type_id, array(2, 3, 4, 5, 6))) ||
      Severity: Minor
      Found in lib/Locos/Utility/LocomotiveUtility.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

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

                  } else {
                      if (strlen($loco_num) === 5 && preg_match("/([a-zA-Z]{1})([0-9]{4})/", $loco_num)) {
                          $params[] = sprintf("%s %s", substr($loco_num, 0, 2), substr($loco_num, 2, 3));
                          $query = "SELECT loco_id FROM loco_unit WHERE class_id = ? AND (loco_num = ? OR loco_num = ?)";
                      }

      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

      Avoid assigning values to variables in if clauses and the like (line '40', column '14').
      Open

          public static function fetchLocomotive(Locomotive $Loco) {
      
              $AppCore = new AppCore;
      
              $Memcached = AppCore::getMemcached();

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

      Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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

              } else {
                  $data['date_modified'] = time();
              }

      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

      Avoid assigning values to variables in if clauses and the like (line '244', column '14').
      Open

          private static function getLocoIDFromClassIDAndLocoNumber($class_id, $loco_num) {
      
              $Memcached = AppCore::getMemcached();
              $Database = (new AppCore)->getDatabaseConnection();
      
      

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

      Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

      Avoid assigning values to variables in if clauses and the like (line '314', column '14').
      Open

          public static function getClassId($slug) {
      
              $Memcached = AppCore::getMemcached();
              $Database = (new AppCore)->getDatabaseConnection();
      
      

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

      Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

      Avoid assigning values to variables in if clauses and the like (line '220', column '14').
      Open

          private static function getClassIDFromSlug($slug) {
      
              $Memcached = AppCore::getMemcached();
              $Database = (new AppCore)->getDatabaseConnection();
              $slug_mckey = sprintf("railpage:loco.id;fromslug=%s;v2", $slug);

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

      Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

      Avoid assigning values to variables in if clauses and the like (line '291', column '13').
      Open

          public static function getLocoId($class, $number) {
      
              $timer = Debug::getTimer();
      
              if (!filter_var($class, FILTER_VALIDATE_INT) && is_string($class)) {

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

      Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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

          public static function getLiveriesForLocomotive($Loco) {
      
              if ($Loco instanceof Locomotive) {
                  $Loco = $Loco->id;
              }
      Severity: Major
      Found in lib/Locos/Utility/LocomotiveUtility.php and 1 other location - About 3 hrs to fix
      lib/Locos/Utility/LocomotiveUtility.php on lines 396..412

      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 85.

      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 static function getLiveriesForLocomotiveClass($LocoClass) {
      
              if ($LocoClass instanceof LocoClass) {
                  $LocoClass = $LocoClass->id;
              }
      Severity: Major
      Found in lib/Locos/Utility/LocomotiveUtility.php and 1 other location - About 3 hrs to fix
      lib/Locos/Utility/LocomotiveUtility.php on lines 370..387

      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 85.

      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

              if (!$id = $Memcached->fetch($slugkey)) {
                  $id = $Database->fetchOne("SELECT id FROM loco_class WHERE slug = ?", $slug);
      
                  $Memcached->save($slugkey, $id, strtotime("+1 year"));
              }
      Severity: Major
      Found in lib/Locos/Utility/LocomotiveUtility.php and 1 other location - About 2 hrs to fix
      lib/Locos/Utility/LocomotiveUtility.php on lines 220..224

      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 55.

      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

              if (!$result = $Memcached->fetch($slug_mckey)) {
                  $result = $Database->fetchOne("SELECT id FROM loco_class WHERE slug = ?", $slug);
      
                  $Memcached->save($slug_mckey, $result, strtotime("+1 year"));
              }
      Severity: Major
      Found in lib/Locos/Utility/LocomotiveUtility.php and 1 other location - About 2 hrs to fix
      lib/Locos/Utility/LocomotiveUtility.php on lines 314..318

      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 55.

      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

              if (in_array($Loco->class_id, array(2, 3, 4, 5, 6)) ||
                      ($Loco->Class instanceof LocoClass && in_array($Loco->Class->type_id, array(2, 3, 4, 5, 6))) ||
      Severity: Major
      Found in lib/Locos/Utility/LocomotiveUtility.php and 1 other location - About 1 hr to fix
      lib/Locos/Utility/LocomotiveUtility.php on lines 72..74

      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 43.

      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

              if (!empty($Loco->builders_num)) {
                  $bits[] = sprintf("as %s ", $Loco->builders_num);
              }
      Severity: Major
      Found in lib/Locos/Utility/LocomotiveUtility.php and 1 other location - About 1 hr to fix
      lib/Locos/Utility/LocomotiveUtility.php on lines 192..194

      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 32.

      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

                      if (!empty($Loco->operator)) {
                          $bits[] = sprintf(" and can be seen on trains operated by %s", $Loco->operator);
                      }
      Severity: Major
      Found in lib/Locos/Utility/LocomotiveUtility.php and 1 other location - About 1 hr to fix
      lib/Locos/Utility/LocomotiveUtility.php on lines 163..165

      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 32.

      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

                      $bits[] = sprintf("On %s, it was withdrawn for preservation. ", $Date->Date->format("F j, Y"));
      Severity: Minor
      Found in lib/Locos/Utility/LocomotiveUtility.php and 1 other location - About 50 mins to fix
      lib/Locos/Utility/LocomotiveUtility.php on lines 135..135

      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 27.

      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

                      $bits[] = sprintf("It was scrapped on %s", $Date->Date->format("F j, Y"));
      Severity: Minor
      Found in lib/Locos/Utility/LocomotiveUtility.php and 1 other location - About 50 mins to fix
      lib/Locos/Utility/LocomotiveUtility.php on lines 131..131

      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 27.

      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

                  case 9: // Under restoration
                      $bits[] = sprintf("\n%s is currently under restoration.", $Loco->number);
                      break;
      Severity: Minor
      Found in lib/Locos/Utility/LocomotiveUtility.php and 1 other location - About 45 mins to fix
      lib/Locos/Utility/LocomotiveUtility.php on lines 184..186

      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 26.

      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

                  case 4: // Preserved - static
                      $bits[] = sprintf("\n%s is preserved statically", $Loco->number);
                      break;
      Severity: Minor
      Found in lib/Locos/Utility/LocomotiveUtility.php and 1 other location - About 45 mins to fix
      lib/Locos/Utility/LocomotiveUtility.php on lines 198..200

      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 26.

      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

                  $Loco->number = str_replace(" ", "", $Loco->number);
      Severity: Minor
      Found in lib/Locos/Utility/LocomotiveUtility.php and 1 other location - About 40 mins to fix
      lib/fwlink.php on lines 138..138

      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 24.

      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

                  "asset_id" => $Loco->Asset instanceof Asset ? $Loco->Asset->id : 0
      Severity: Major
      Found in lib/Locos/Utility/LocomotiveUtility.php and 3 other locations - About 35 mins to fix
      lib/Downloads/Category.php on lines 167..167
      lib/Downloads/Download.php on lines 332..332
      lib/Forums/Forum.php on lines 329..329

      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 22.

      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

                  $return[$row['loco_id']] = array(
                      "id" => $row['loco_id'],
                      "name" => $row['number']
                  );
      Severity: Major
      Found in lib/Locos/Utility/LocomotiveUtility.php and 3 other locations - About 30 mins to fix
      lib/Images/Exif.php on lines 294..294
      lib/Images/Provider/FiveHundredPx.php on lines 323..326
      lib/Images/Utility/Geoplace.php on lines 111..114

      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

      The parameter $Loco is not named in camelCase.
      Open

          public static function getConstructionDate(Locomotive $Loco) {
      
              $dates = $Loco->loadDates();
              $dates = array_reverse($dates, true);
      
      

      CamelCaseParameterName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name parameters.

      Example

      class ClassName {
          public function doSomething($user_name) {
          }
      }

      Source

      The parameter $class_id is not named in camelCase.
      Open

          private static function getLocoIDFromClassIDAndLocoNumber($class_id, $loco_num) {
      
              $Memcached = AppCore::getMemcached();
              $Database = (new AppCore)->getDatabaseConnection();
      
      

      CamelCaseParameterName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name parameters.

      Example

      class ClassName {
          public function doSomething($user_name) {
          }
      }

      Source

      The parameter $Loco is not named in camelCase.
      Open

          public static function getLiveriesForLocomotive($Loco) {
      
              if ($Loco instanceof Locomotive) {
                  $Loco = $Loco->id;
              }

      CamelCaseParameterName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name parameters.

      Example

      class ClassName {
          public function doSomething($user_name) {
          }
      }

      Source

      The parameter $Livery is not named in camelCase.
      Open

          public static function getLocosFromLivery($Livery) {
      
              if ($Livery instanceof Livery) {
                  $Livery = $Livery->id;
              }

      CamelCaseParameterName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name parameters.

      Example

      class ClassName {
          public function doSomething($user_name) {
          }
      }

      Source

      The parameter $Loco is not named in camelCase.
      Open

          public static function getDescriptionBits_Status(Locomotive $Loco, $bits) {
      
              switch ($Loco->status_id) {
                  case 4: // Preserved - static
                      $bits[] = sprintf("\n%s is preserved statically", $Loco->number);

      CamelCaseParameterName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name parameters.

      Example

      class ClassName {
          public function doSomething($user_name) {
          }
      }

      Source

      The parameter $Loco is not named in camelCase.
      Open

          public static function getSubmitData(Locomotive $Loco) {
      
              // Drop whitespace from loco numbers of all types except steam
              if (in_array($Loco->class_id, array(2, 3, 4, 5, 6)) ||
                      ($Loco->Class instanceof LocoClass && in_array($Loco->Class->type_id, array(2, 3, 4, 5, 6))) ||

      CamelCaseParameterName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name parameters.

      Example

      class ClassName {
          public function doSomething($user_name) {
          }
      }

      Source

      The parameter $loco_num is not named in camelCase.
      Open

          private static function getLocoIDFromClassIDAndLocoNumber($class_id, $loco_num) {
      
              $Memcached = AppCore::getMemcached();
              $Database = (new AppCore)->getDatabaseConnection();
      
      

      CamelCaseParameterName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name parameters.

      Example

      class ClassName {
          public function doSomething($user_name) {
          }
      }

      Source

      The parameter $LocoClass is not named in camelCase.
      Open

          public static function getLiveriesForLocomotiveClass($LocoClass) {
      
              if ($LocoClass instanceof LocoClass) {
                  $LocoClass = $LocoClass->id;
              }

      CamelCaseParameterName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name parameters.

      Example

      class ClassName {
          public function doSomething($user_name) {
          }
      }

      Source

      The parameter $Loco is not named in camelCase.
      Open

          public static function getDescriptionBits_Dates(Locomotive $Loco, $bits) {
      
              $dates = $Loco->loadDates();
              $dates = array_reverse($dates);
      
      

      CamelCaseParameterName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name parameters.

      Example

      class ClassName {
          public function doSomething($user_name) {
          }
      }

      Source

      The parameter $Loco is not named in camelCase.
      Open

          public static function fetchLocomotive(Locomotive $Loco) {
      
              $AppCore = new AppCore;
      
              $Memcached = AppCore::getMemcached();

      CamelCaseParameterName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name parameters.

      Example

      class ClassName {
          public function doSomething($user_name) {
          }
      }

      Source

      The parameter $Loco is not named in camelCase.
      Open

          public static function getDescriptionBits_Manufacturer(Locomotive $Loco, $bits) {
      
              $bits[] = "Built ";
      
              if (!empty($Loco->builders_num)) {

      CamelCaseParameterName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name parameters.

      Example

      class ClassName {
          public function doSomething($user_name) {
          }
      }

      Source

      Function closing brace must go on the next line following the body; found 1 blank lines before brace
      Open

          }

      Function closing brace must go on the next line following the body; found 1 blank lines before brace
      Open

          }

      Function closing brace must go on the next line following the body; found 1 blank lines before brace
      Open

          }

      Blank line found at start of control structure
      Open

              if (!$loco_id = $Memcached->fetch(sprintf("railpage:loco.id;fromclass=%s;fromnumber=%s", $class_id, $loco_num))) {

      Function closing brace must go on the next line following the body; found 1 blank lines before brace
      Open

          }

      Function closing brace must go on the next line following the body; found 1 blank lines before brace
      Open

          }

      Function closing brace must go on the next line following the body; found 1 blank lines before brace
      Open

          }

      Function closing brace must go on the next line following the body; found 1 blank lines before brace
      Open

          }

      Function closing brace must go on the next line following the body; found 1 blank lines before brace
      Open

          }

      Blank line found at start of control structure
      Open

              if (!$row = $Memcached->fetch($Loco->mckey)) {

      Function closing brace must go on the next line following the body; found 1 blank lines before brace
      Open

          }

      Function closing brace must go on the next line following the body; found 1 blank lines before brace
      Open

          }

      Function closing brace must go on the next line following the body; found 1 blank lines before brace
      Open

          }

      There are no issues that match your filters.

      Category
      Status