MPOS/php-mpos

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

Summary

Maintainability
F
6 days
Test Coverage

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

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


/*
Severity: Major
Found in include/classes/statistics.class.php - About 1 day to fix

    Statistics has 33 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Statistics extends Base {
      protected $table = 'statistics_shares';
      protected $table_user_stats = 'statistics_users';
      private $getcache = true;
    
    
    Severity: Minor
    Found in include/classes/statistics.class.php - About 4 hrs to fix

      Function getTopContributors has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

        public function getTopContributors($type='shares', $limit=15) {
          $this->debug->append("STA " . __METHOD__, 4);
          switch ($type) {
          case 'shares':
            if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $type . $limit)) return $data;
      Severity: Minor
      Found in include/classes/statistics.class.php - About 3 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

      Method getTopContributors has 75 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        public function getTopContributors($type='shares', $limit=15) {
          $this->debug->append("STA " . __METHOD__, 4);
          switch ($type) {
          case 'shares':
            if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $type . $limit)) return $data;
      Severity: Major
      Found in include/classes/statistics.class.php - About 3 hrs to fix

        Function getAllUserStats has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

          public function getAllUserStats($filter='%',$limit=1,$start=0) {
            $this->debug->append("STA " . __METHOD__, 4);
            $sql = "
              SELECT
                a.id AS id,
        Severity: Minor
        Found in include/classes/statistics.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

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

          public function getAllUserStats($filter='%',$limit=1,$start=0) {
            $this->debug->append("STA " . __METHOD__, 4);
            $sql = "
              SELECT
                a.id AS id,
        Severity: Major
        Found in include/classes/statistics.class.php - About 2 hrs to fix

          Method getLastBlocksbyTime has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            function getLastBlocksbyTime() {
              $this->debug->append("STA " . __METHOD__, 4);
              if ($data = $this->memcache->get(__FUNCTION__)) return $data;
              $stmt = $this->mysqli->prepare("
                SELECT
          Severity: Major
          Found in include/classes/statistics.class.php - About 2 hrs to fix

            Method fetchAllUserMiningStats has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              public function fetchAllUserMiningStats($interval=180) {
                $this->debug->append("STA " . __METHOD__, 4);
                $stmt = $this->mysqli->prepare("
                  SELECT
                    a.id AS id,
            Severity: Minor
            Found in include/classes/statistics.class.php - About 1 hr to fix

              Method getUserMiningStats has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                public function getUserMiningStats($username, $account_id=NULL, $interval=180) {
                  $this->debug->append("STA " . __METHOD__, 4);
                  // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
                  if ($this->getGetCache() && $data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
                    if (array_key_exists($account_id, $data['data'])) {
              Severity: Minor
              Found in include/classes/statistics.class.php - About 1 hr to fix

                Method getAllUserShares has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  public function getAllUserShares() {
                    $this->debug->append("STA " . __METHOD__, 4);
                    if (! $data = $this->memcache->get(STATISTICS_ALL_USER_SHARES)) {
                      $data['share_id'] = 0;
                      $data['data'] = array();
                Severity: Minor
                Found in include/classes/statistics.class.php - About 1 hr to fix

                  Function getPPSValue has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                  Open

                    public function getPPSValue() {
                      // Fetch RPC difficulty
                      if ($this->bitcoin->can_connect() === true) {
                        $dDifficulty = $this->bitcoin->getdifficulty();
                      } else {
                  Severity: Minor
                  Found in include/classes/statistics.class.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 getUserEstimates has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    public function getUserEstimates($value1, $value2, $dDonate, $bNoFees, $ppsvalue=0) {
                      $this->debug->append("STA " . __METHOD__, 4);
                      if ($this->config['payout_system'] != 'pps') {
                        if (@$value1['valid'] > 0  && @$value2['valid'] > 0) {
                          $this->config['reward_type'] == 'fixed' ? $reward = $this->config['reward'] : $reward = $this->block->getAverageAmount();
                  Severity: Minor
                  Found in include/classes/statistics.class.php - About 1 hr to fix

                    Function getAllUserShares has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                      public function getAllUserShares() {
                        $this->debug->append("STA " . __METHOD__, 4);
                        if (! $data = $this->memcache->get(STATISTICS_ALL_USER_SHARES)) {
                          $data['share_id'] = 0;
                          $data['data'] = array();
                    Severity: Minor
                    Found in include/classes/statistics.class.php - About 55 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 getUserEstimates has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                      public function getUserEstimates($value1, $value2, $dDonate, $bNoFees, $ppsvalue=0) {
                        $this->debug->append("STA " . __METHOD__, 4);
                        if ($this->config['payout_system'] != 'pps') {
                          if (@$value1['valid'] > 0  && @$value2['valid'] > 0) {
                            $this->config['reward_type'] == 'fixed' ? $reward = $this->config['reward'] : $reward = $this->block->getAverageAmount();
                    Severity: Minor
                    Found in include/classes/statistics.class.php - About 55 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

                    Method getUserEstimates has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                      public function getUserEstimates($value1, $value2, $dDonate, $bNoFees, $ppsvalue=0) {
                    Severity: Minor
                    Found in include/classes/statistics.class.php - About 35 mins to fix

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

                        public function getExpectedTimePerBlock($type='network',$hashrate = 0){
                          if ($data = $this->memcache->get(__FUNCTION__)) return $data;
                      
                          if ($this->bitcoin->can_connect() === true) {
                            if ($type == 'network') {
                      Severity: Minor
                      Found in include/classes/statistics.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 $this->memcache->setStaticCache(__FUNCTION__ . $type . $limit, $aData);
                      Severity: Major
                      Found in include/classes/statistics.class.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                              if ($this->getGetCache() && $data = $this->memcache->getStatic(__FUNCTION__ . $type . $limit)) return $data;
                        Severity: Major
                        Found in include/classes/statistics.class.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                return $this->sqlError();
                          Severity: Major
                          Found in include/classes/statistics.class.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                  return $this->sqlError();
                            Severity: Major
                            Found in include/classes/statistics.class.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                  return $this->sqlError();
                              Severity: Major
                              Found in include/classes/statistics.class.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                    return $this->sqlError();
                                Severity: Major
                                Found in include/classes/statistics.class.php - About 30 mins to fix

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

                                    public function getUserMiningStats($username, $account_id=NULL, $interval=180) {
                                      $this->debug->append("STA " . __METHOD__, 4);
                                      // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
                                      if ($this->getGetCache() && $data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
                                        if (array_key_exists($account_id, $data['data'])) {
                                  Severity: Minor
                                  Found in include/classes/statistics.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 getUserShares has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                    public function getUserShares($username, $account_id=NULL) {
                                      $this->debug->append("STA " . __METHOD__, 4);
                                      // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
                                      if ($data = $this->memcache->get(STATISTICS_ALL_USER_SHARES)) {
                                        if (array_key_exists($account_id, $data['data']))
                                  Severity: Minor
                                  Found in include/classes/statistics.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 storeAllUserMiningStatsSnapshot has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                    public function storeAllUserMiningStatsSnapshot($aData) {
                                      $this->debug->append("STA " . __METHOD__, 4);
                                      if (!isset($aData['data'])) return false;
                                      // initilize
                                      $timestamp = time();    // Store all entries with the same timestamp to reduce cardinality
                                  Severity: Minor
                                  Found in include/classes/statistics.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 getRoundShares has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                    public function getRoundShares() {
                                      $this->debug->append("STA " . __METHOD__, 4);
                                      // Try the statistics cron cache, then function cache, then fallback to SQL
                                      if ($data = $this->memcache->get(STATISTICS_ALL_USER_SHARES)) {
                                        $this->debug->append("Found data in statistics cache", 2);
                                  Severity: Minor
                                  Found in include/classes/statistics.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

                                    public function getCountAllActiveUsers($interval=120) {
                                      $this->debug->append("STA " . __METHOD__, 4);
                                      if ($data = $this->memcache->get(__FUNCTION__)) return $data;
                                      $stmt = $this->mysqli->prepare("
                                        SELECT COUNT(DISTINCT(SUBSTRING_INDEX( `username` , '.', 1 ))) AS total
                                  Severity: Major
                                  Found in include/classes/statistics.class.php and 1 other location - About 3 hrs to fix
                                  include/classes/worker.class.php on lines 243..254

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

                                  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