railpage/railpagecore

View on GitHub
lib/Railcams/Provider/Flickr.php

Summary

Maintainability
F
3 days
Test Coverage

Method getPhoto has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        public function getPhoto($id) {
            $mckey = sprintf("railpage:railcam.provider=%s;railcam.image=%d", self::PROVIDER_NAME, $id);
            
            if ($this->photo = $this->Memcached->fetch($mckey)) {
                return $this->photo;
Severity: Minor
Found in lib/Railcams/Provider/Flickr.php - About 1 hr to fix

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

            public function getPhoto($id) {
                $mckey = sprintf("railpage:railcam.provider=%s;railcam.image=%d", self::PROVIDER_NAME, $id);
                
                if ($this->photo = $this->Memcached->fetch($mckey)) {
                    return $this->photo;
    Severity: Minor
    Found in lib/Railcams/Provider/Flickr.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

    Consider simplifying this complex logical expression.
    Open

                if (empty($this->oauthToken) || empty($this->oauth_secret) || empty($this->flickrApiKey) ||
                    is_null($this->oauthToken) || is_null($this->oauth_secret) || is_null($this->flickrApiKey)) {
                    return false;
                }
    Severity: Major
    Found in lib/Railcams/Provider/Flickr.php - About 40 mins to fix

      The method __construct has a boolean flag argument $params, which is a certain sign of a Single Responsibility Principle violation.
      Open

              public function __construct($params = false) {
      Severity: Minor
      Found in lib/Railcams/Provider/Flickr.php by phpmd

      BooleanArgumentFlag

      Since: 1.4.0

      A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

      Example

      class Foo {
          public function bar($flag = true) {
          }
      }

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

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

              public function getPhoto($id) {
                  $mckey = sprintf("railpage:railcam.provider=%s;railcam.image=%d", self::PROVIDER_NAME, $id);
                  
                  if ($this->photo = $this->Memcached->fetch($mckey)) {
                      return $this->photo;
      Severity: Minor
      Found in lib/Railcams/Provider/Flickr.php by phpmd

      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 getPhoto uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      $return = array(); 
                      
                      if ($return = $this->cn->photos_getInfo($id)) {
                          $return['photo']['sizes'] = $this->cn->photos_getSizes($id);
      Severity: Minor
      Found in lib/Railcams/Provider/Flickr.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

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

              public function getPhoto($id) {
                  $mckey = sprintf("railpage:railcam.provider=%s;railcam.image=%d", self::PROVIDER_NAME, $id);
                  
                  if ($this->photo = $this->Memcached->fetch($mckey)) {
                      return $this->photo;
      Severity: Minor
      Found in lib/Railcams/Provider/Flickr.php by phpmd

      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 unused parameters such as '$itemsPerPage'.
      Open

              public function getPhotos($page, $itemsPerPage) {
      Severity: Minor
      Found in lib/Railcams/Provider/Flickr.php by phpmd

      UnusedFormalParameter

      Since: 0.2

      Avoid passing parameters to methods or constructors and then not using those parameters.

      Example

      class Foo
      {
          private function bar($howdy)
          {
              // $howdy is not used
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

      Avoid unused parameters such as '$page'.
      Open

              public function getPhotos($page, $itemsPerPage) {
      Severity: Minor
      Found in lib/Railcams/Provider/Flickr.php by phpmd

      UnusedFormalParameter

      Since: 0.2

      Avoid passing parameters to methods or constructors and then not using those parameters.

      Example

      class Foo
      {
          private function bar($howdy)
          {
              // $howdy is not used
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

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

              public function setPhoto(Photo $photoObject) {
                  
                  /** 
                   * Flush Memcache
                   */
      Severity: Major
      Found in lib/Railcams/Provider/Flickr.php and 1 other location - About 1 day to fix
      lib/Images/Provider/Flickr.php on lines 304..330

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

      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

                          "author" => array(
                              "id" => $return['photo']['owner']['nsid'],
                              "username" => $return['photo']['owner']['username'],
                              "realname" => $return['photo']['owner']['realname'],
                              "url" => new Url(sprintf("https://www.flickr.com/photos/%s", $return['photo']['owner']['nsid']))
      Severity: Major
      Found in lib/Railcams/Provider/Flickr.php and 1 other location - About 3 hrs to fix
      lib/Images/Provider/Flickr.php on lines 276..281

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

      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 (isset($rs['nextphoto']) && is_array($rs['nextphoto'])) {
                      $return['next'] = array(
                          "id" => $rs['nextphoto']['id'],
                          "title" => isset($rs['nextphoto']['title']) ? $rs['nextphoto']['title'] : "Untitled"
                      );
      Severity: Major
      Found in lib/Railcams/Provider/Flickr.php and 3 other locations - About 3 hrs to fix
      lib/Images/Provider/Flickr.php on lines 369..374
      lib/Images/Provider/Flickr.php on lines 376..381
      lib/Railcams/Provider/Flickr.php on lines 227..232

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

      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 (isset($rs['prevphoto']) && is_array($rs['prevphoto'])) {
                      $return['previous'] = array(
                          "id" => $rs['prevphoto']['id'],
                          "title" => isset($rs['prevphoto']['title']) ? $rs['prevphoto']['title'] : "Untitled"
                      );
      Severity: Major
      Found in lib/Railcams/Provider/Flickr.php and 3 other locations - About 3 hrs to fix
      lib/Images/Provider/Flickr.php on lines 369..374
      lib/Images/Provider/Flickr.php on lines 376..381
      lib/Railcams/Provider/Flickr.php on lines 234..239

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

      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 (isset($return['photo']['lastupdate'])) {
                          $this->photo['dates']['updated'] = new DateTime(sprintf("@%s", $return['photo']['lastupdate'])); 
                      }
      Severity: Major
      Found in lib/Railcams/Provider/Flickr.php and 1 other location - About 2 hrs to fix
      lib/Railcams/Provider/Flickr.php on lines 142..144

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

      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 (isset($return['photo']['dateuploaded'])) {
                          $this->photo['dates']['uploaded'] = new DateTime(sprintf("@%s", $return['photo']['dateuploaded'])); 
                      }
      Severity: Major
      Found in lib/Railcams/Provider/Flickr.php and 1 other location - About 2 hrs to fix
      lib/Railcams/Provider/Flickr.php on lines 146..148

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

      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

                              "taken" => new DateTime($return['photo']['dates']['taken']),
      Severity: Minor
      Found in lib/Railcams/Provider/Flickr.php and 1 other location - About 40 mins to fix
      lib/Images/Provider/Flickr.php on lines 272..272

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

                  $return = array(
                      "previous" => false,
                      "next" => false
                  );
      Severity: Major
      Found in lib/Railcams/Provider/Flickr.php and 2 other locations - About 40 mins to fix
      lib/Images/Provider/Flickr.php on lines 364..367
      lib/Prerender/Prerender.php on lines 124..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 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 3 locations. Consider refactoring.
      Open

                  $mckey = sprintf("railpage:railcam.provider=%s;railcam.image=%d", self::PROVIDER_NAME, $id);
      Severity: Minor
      Found in lib/Railcams/Provider/Flickr.php and 2 other locations - About 40 mins to fix
      lib/Images/Provider/Flickr.php on lines 214..214
      lib/Images/Provider/Flickr.php on lines 436..436

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

      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

      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

              }

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              private $flickrApiKey;

      Line indented incorrectly; expected 12 spaces, found 16
      Open

                      if (isset($return['photo']['dateuploaded'])) {

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              public function getPhotos($page, $itemsPerPage) {

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  }

      Line indented incorrectly; expected 12 spaces, found 16
      Open

                      }

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  }

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              public function isAuthenticated() {

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              public $oauth_secret;

      Line indented incorrectly; expected 12 spaces, found 16
      Open

                      if (isset($return['photo']['lastupdate'])) {

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              }

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  if (is_array($params) && isset($params['oauth_token']) && isset($params['oauth_secret']) && isset($params['api_key'])) {

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  if ($photoObject->title != $this->photo['title'] || $photoObject->description != $this->photo['description']) {

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              public function getPhotoContext(Photo $photoObject) {

      Line indented incorrectly; expected 0 spaces, found 4
      Open

          }

      Line indented incorrectly; expected 12 spaces, found 16
      Open

                      }

      Line indented incorrectly; expected 12 spaces, found 16
      Open

                      }

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              public function deletePhoto(Photo $photoObject) {

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  }

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  }

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              }

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              }

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  if (isset($rs['prevphoto']) && is_array($rs['prevphoto'])) {

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              }

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  if ($this->photo = $this->Memcached->fetch($mckey)) {

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              public function setPhoto(Photo $photoObject) {

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              }

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  if (empty($this->oauthToken) || empty($this->oauth_secret) || empty($this->flickrApiKey) ||

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              public function getProviderName() {

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  }

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              private $oauthToken;

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              private $cn;

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  } else {

      Line indented incorrectly; expected 12 spaces, found 16
      Open

                      if ($return = $this->cn->photos_getInfo($id)) {

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              private $photo;

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              public function __construct($params = false) {

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              public function getPhoto($id) {

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  if (isset($rs['nextphoto']) && is_array($rs['nextphoto'])) {

      Line indented incorrectly; expected 12 spaces, found 16
      Open

                      }

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              }

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              }

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  }

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              }

      Line indented incorrectly; expected 0 spaces, found 4
      Open

          class Flickr extends AppCore implements ProviderInterface {

      Line indented incorrectly; expected 12 spaces, found 16
      Open

                      if (!$result) {

      There are no issues that match your filters.

      Category
      Status