railpage/railpagecore

View on GitHub
lib/Images/Favourites.php

Summary

Maintainability
D
1 day
Test Coverage

Function setUserFavourite has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function setUserFavourite() {
        
        /**
         * Because I'll no doubt get confused - frequently - at the order of parameters, 
         * let's just be a sneaky bastard and check each parameter
Severity: Minor
Found in lib/Images/Favourites.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 setUserFavourite has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function setUserFavourite() {
        
        /**
         * Because I'll no doubt get confused - frequently - at the order of parameters, 
         * let's just be a sneaky bastard and check each parameter
Severity: Minor
Found in lib/Images/Favourites.php - About 1 hr to fix

    Function removeUserFavourite has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public function removeUserFavourite() {
            
            /**
             * Because I'll no doubt get confused - frequently - at the order of parameters, 
             * let's just be a sneaky bastard and check each parameter
    Severity: Minor
    Found in lib/Images/Favourites.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 removeUserFavourite has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function removeUserFavourite() {
            
            /**
             * Because I'll no doubt get confused - frequently - at the order of parameters, 
             * let's just be a sneaky bastard and check each parameter
    Severity: Minor
    Found in lib/Images/Favourites.php - About 1 hr to fix

      The method setUserFavourite() has an NPath complexity of 480. The configured NPath complexity threshold is 200.
      Open

          public function setUserFavourite() {
              
              /**
               * Because I'll no doubt get confused - frequently - at the order of parameters, 
               * let's just be a sneaky bastard and check each parameter
      Severity: Minor
      Found in lib/Images/Favourites.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 setUserFavourite() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
      Open

          public function setUserFavourite() {
              
              /**
               * Because I'll no doubt get confused - frequently - at the order of parameters, 
               * let's just be a sneaky bastard and check each parameter
      Severity: Minor
      Found in lib/Images/Favourites.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

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

              foreach (func_get_args() as $arg) {
                  if ($arg instanceof User) {
                      $User = $arg;
                      continue;
                  }
      Severity: Major
      Found in lib/Images/Favourites.php and 1 other location - About 1 hr to fix
      lib/Images/Favourites.php on lines 162..172

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

      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 2 locations. Consider refactoring.
      Open

              foreach (func_get_args() as $arg) {
                  if ($arg instanceof User) {
                      $User = $arg;
                      continue;
                  }
      Severity: Major
      Found in lib/Images/Favourites.php and 1 other location - About 1 hr to fix
      lib/Images/Favourites.php on lines 96..106

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

      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 25 locations. Consider refactoring.
      Open

              if (!filter_var($User->id, FILTER_VALIDATE_INT)) {
                  throw new InvalidArgumentException("It looks like you're not logged in");
              }
      Severity: Major
      Found in lib/Images/Favourites.php and 24 other locations - About 1 hr to fix
      lib/Downloads/Download.php on lines 313..315
      lib/Events/Event.php on lines 425..427
      lib/Events/Events.php on lines 130..132
      lib/Images/Competition.php on lines 624..626
      lib/Images/Competition.php on lines 654..656
      lib/Images/Competition.php on lines 823..825
      lib/Images/Competition.php on lines 860..862
      lib/Images/Favourites.php on lines 112..114
      lib/Jobs/Classification.php on lines 80..82
      lib/Locations/Location.php on lines 406..408
      lib/Locations/Location.php on lines 410..412
      lib/Locos/Locomotive.php on lines 622..624
      lib/Locos/Locomotive.php on lines 626..628
      lib/Locos/Locomotive.php on lines 897..899
      lib/News/Article.php on lines 361..363
      lib/News/Article.php on lines 834..836
      lib/Newsletters/Newsletters.php on lines 135..137
      lib/PrivateMessages/Message.php on lines 244..246
      lib/PrivateMessages/Message.php on lines 452..454
      lib/Railcams/Photo.php on lines 330..332
      lib/Railcams/Storage.php on lines 224..226
      lib/Sightings/Sighting.php on lines 133..135
      lib/Users/Group.php on lines 236..238
      lib/Warnings/Warning.php on lines 209..211

      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 25 locations. Consider refactoring.
      Open

              if (!filter_var($User->id, FILTER_VALIDATE_INT)) {
                  throw new InvalidArgumentException("It looks like you're not logged in");
              }
      Severity: Major
      Found in lib/Images/Favourites.php and 24 other locations - About 1 hr to fix
      lib/Downloads/Download.php on lines 313..315
      lib/Events/Event.php on lines 425..427
      lib/Events/Events.php on lines 130..132
      lib/Images/Competition.php on lines 624..626
      lib/Images/Competition.php on lines 654..656
      lib/Images/Competition.php on lines 823..825
      lib/Images/Competition.php on lines 860..862
      lib/Images/Favourites.php on lines 178..180
      lib/Jobs/Classification.php on lines 80..82
      lib/Locations/Location.php on lines 406..408
      lib/Locations/Location.php on lines 410..412
      lib/Locos/Locomotive.php on lines 622..624
      lib/Locos/Locomotive.php on lines 626..628
      lib/Locos/Locomotive.php on lines 897..899
      lib/News/Article.php on lines 361..363
      lib/News/Article.php on lines 834..836
      lib/Newsletters/Newsletters.php on lines 135..137
      lib/PrivateMessages/Message.php on lines 244..246
      lib/PrivateMessages/Message.php on lines 452..454
      lib/Railcams/Photo.php on lines 330..332
      lib/Railcams/Storage.php on lines 224..226
      lib/Sightings/Sighting.php on lines 133..135
      lib/Users/Group.php on lines 236..238
      lib/Warnings/Warning.php on lines 209..211

      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 4 locations. Consider refactoring.
      Open

                  $row['url'] = ImageUrlUtility::CreateFromImageID($row['image_id'])->getURLs(); 
      Severity: Major
      Found in lib/Images/Favourites.php and 3 other locations - About 45 mins to fix
      lib/Images/PhotoOfTheWeek.php on lines 153..153
      lib/Images/PhotoOfTheWeek.php on lines 215..215
      lib/Images/Utility/Finder.php on lines 648..648

      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

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

              if (!isset($Image->author->User) || !$Image->author->User instanceof User) {
                  $Image = ImageUpdater::updateAuthor($Image);
              }
      Severity: Major
      Found in lib/Images/Favourites.php and 2 other locations - About 45 mins to fix
      lib/Locos/Correction.php on lines 316..318
      lib/Users/Timeline.php on lines 203..205

      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

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

              if ($User === false) {
                  throw new InvalidArgumentException("No or invalid user object provided"); 
              }
      Severity: Major
      Found in lib/Images/Favourites.php and 5 other locations - About 35 mins to fix
      lib/Forums/Category.php on lines 88..90
      lib/Forums/Forum.php on lines 185..187
      lib/Images/Favourites.php on lines 108..110
      lib/Images/Favourites.php on lines 116..118
      lib/Images/Favourites.php on lines 182..184

      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 6 locations. Consider refactoring.
      Open

              if ($Image === false) {
                  throw new InvalidArgumentException("No or invalid image object provided"); 
              }
      Severity: Major
      Found in lib/Images/Favourites.php and 5 other locations - About 35 mins to fix
      lib/Forums/Category.php on lines 88..90
      lib/Forums/Forum.php on lines 185..187
      lib/Images/Favourites.php on lines 108..110
      lib/Images/Favourites.php on lines 174..176
      lib/Images/Favourites.php on lines 182..184

      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 6 locations. Consider refactoring.
      Open

              if ($Image === false) {
                  throw new InvalidArgumentException("No or invalid image object provided"); 
              }
      Severity: Major
      Found in lib/Images/Favourites.php and 5 other locations - About 35 mins to fix
      lib/Forums/Category.php on lines 88..90
      lib/Forums/Forum.php on lines 185..187
      lib/Images/Favourites.php on lines 108..110
      lib/Images/Favourites.php on lines 116..118
      lib/Images/Favourites.php on lines 174..176

      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 6 locations. Consider refactoring.
      Open

              if ($User === false) {
                  throw new InvalidArgumentException("No or invalid user object provided"); 
              }
      Severity: Major
      Found in lib/Images/Favourites.php and 5 other locations - About 35 mins to fix
      lib/Forums/Category.php on lines 88..90
      lib/Forums/Forum.php on lines 185..187
      lib/Images/Favourites.php on lines 116..118
      lib/Images/Favourites.php on lines 174..176
      lib/Images/Favourites.php on lines 182..184

      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 6 locations. Consider refactoring.
      Open

              $query = sprintf($query, $this->db->quote(intval($User->id)), $this->db->quote(intval($Image->id))); 
      Severity: Major
      Found in lib/Images/Favourites.php and 5 other locations - About 30 mins to fix
      lib/Images/Favourites.php on lines 137..137
      lib/Images/Screener.php on lines 103..103
      lib/Images/Screener.php on lines 106..106
      lib/Images/Screener.php on lines 148..148
      lib/Images/Screener.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

      The parameter $Image is not named in camelCase.
      Open

          public function getImageFavourites(Image $Image) {
              
              $query = "SELECT f.*, u.username 
                  FROM image_favourites AS f 
                      LEFT JOIN nuke_users AS u ON f.user_id = u.user_id
      Severity: Minor
      Found in lib/Images/Favourites.php by phpmd

      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 $User is not named in camelCase.
      Open

          public function getUserFavourites(User $User) {
              
              $query = "SELECT f.*, i.title, i.description, i.meta
                  FROM image_favourites AS f 
                      LEFT JOIN image AS i ON f.image_id = i.image_id
      Severity: Minor
      Found in lib/Images/Favourites.php by phpmd

      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

          }
      Severity: Minor
      Found in lib/Images/Favourites.php by phpcodesniffer

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

          }
      Severity: Minor
      Found in lib/Images/Favourites.php by phpcodesniffer

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

          }
      Severity: Minor
      Found in lib/Images/Favourites.php by phpcodesniffer

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

          }
      Severity: Minor
      Found in lib/Images/Favourites.php by phpcodesniffer

      There are no issues that match your filters.

      Category
      Status