MPOS/php-mpos

View on GitHub
include/classes/share.class.php

Summary

Maintainability
C
1 day
Test Coverage

File share.class.php has 284 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;

class Share Extends Base {
  protected $table = 'shares';
Severity: Minor
Found in include/classes/share.class.php - About 2 hrs to fix

    Method findUpstreamShare has 62 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      public function findUpstreamShare($aBlock, $last=0) {
        // Many use stratum, so we create our stratum check first
        $version = pack("I*", sprintf('%08d', $aBlock['version']));
        $previousblockhash = pack("H*", swapEndian($aBlock['previousblockhash']));
        $merkleroot = pack("H*", swapEndian($aBlock['merkleroot']) );
    Severity: Major
    Found in include/classes/share.class.php - About 2 hrs to fix

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

        public function findUpstreamShare($aBlock, $last=0) {
          // Many use stratum, so we create our stratum check first
          $version = pack("I*", sprintf('%08d', $aBlock['version']));
          $previousblockhash = pack("H*", swapEndian($aBlock['previousblockhash']));
          $merkleroot = pack("H*", swapEndian($aBlock['merkleroot']) );
      Severity: Minor
      Found in include/classes/share.class.php - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function deleteAccountedShares has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        public function deleteAccountedShares($current_upstream, $previous_upstream=0) {
          // Fallbacks if unset
          if (!isset($this->config['purge']['shares'])) $this->config['purge']['shares'] = 25000;
          if (!isset($this->config['purge']['sleep'])) $this->config['purge']['sleep'] = 1;
      
      
      Severity: Minor
      Found in include/classes/share.class.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

      Avoid too many return statements within this method.
      Open

              return true;
      Severity: Major
      Found in include/classes/share.class.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

            return false;
        Severity: Major
        Found in include/classes/share.class.php - About 30 mins to fix

          Function updateShareById has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            public function updateShareById($id, $data) {
              $this->debug->append("STA " . __METHOD__, 4);
              $sql = "UPDATE $this->table SET";
              $start = true;
              // Remove ID column
          Severity: Minor
          Found in include/classes/share.class.php - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function getArchiveShares has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            function getArchiveShares($iCount) {
              $iMaxId = $this->getMaxArchiveShareId();
              $iMinId = $this->getMinArchiveShareId($iCount);
              $stmt = $this->mysqli->prepare("
                SELECT
          Severity: Minor
          Found in include/classes/share.class.php - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

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

              if ($this->checkStmt($stmt) && $stmt->bind_param('s', $ppheader) && $stmt->execute() && $result = $stmt->get_result()) {
                $this->oUpstream = $result->fetch_object();
                $this->share_type = 'pp_solution';
                if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id))
                  return true;
          Severity: Major
          Found in include/classes/share.class.php and 1 other location - About 1 hr to fix
          include/classes/share.class.php on lines 295..300

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

          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 ($this->checkStmt($stmt) && $stmt->bind_param('s', $scrypt_hash) && $stmt->execute() && $result = $stmt->get_result()) {
                $this->oUpstream = $result->fetch_object();
                $this->share_type = 'stratum_solution';
                if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id))
                  return true;
          Severity: Major
          Found in include/classes/share.class.php and 1 other location - About 1 hr to fix
          include/classes/share.class.php on lines 306..311

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

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

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

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

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

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status