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;
/*
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;
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;
- Read upRead up
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;
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,
- Read upRead up
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,
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
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,
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'])) {
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();
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 {
- Read upRead up
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();
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();
- Read upRead up
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();
- Read upRead up
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) {
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') {
- Read upRead up
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);
Avoid too many return
statements within this method. Open
if ($this->getGetCache() && $data = $this->memcache->getStatic(__FUNCTION__ . $type . $limit)) return $data;
Avoid too many return
statements within this method. Open
return $this->sqlError();
Avoid too many return
statements within this method. Open
return $this->sqlError();
Avoid too many return
statements within this method. Open
return $this->sqlError();
Avoid too many return
statements within this method. Open
return $this->sqlError();
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'])) {
- Read upRead up
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']))
- Read upRead up
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
- Read upRead up
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);
- Read upRead up
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
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76