Completed
Push — master ( 762814...853e43 )
by
unknown
9s
created

CommodityChannelIndexIndicator::__invoke()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 20
loc 20
ccs 0
cts 10
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 4
nop 2
crap 20
1
<?php
2
3
namespace Laratrade\Indicators;
4
5
use Illuminate\Support\Collection;
6
use Laratrade\Indicators\Contracts\Indicator;
7
use Laratrade\Indicators\Exceptions\NotEnoughDataPointsException;
8
9
/**
10
 * Commodity Channel Index
11
 *
12
 * @see https://www.investopedia.com/terms/c/commoditychannelindex.asp?ad=dirN&qo=investopediaSiteSearch&qsrc=0&o=40186
13
 *
14
 * The Commodity Channel Index​ (CCI) is a momentum based technical trading tool used most often to help
15
 * determine when an investment vehicle is reaching a condition of being overbought or oversold.
16
 *
17
 */
18 View Code Duplication
class CommodityChannelIndexIndicator implements Indicator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
21
    public function __invoke(Collection $ohlcv, int $period = 14): int
22
    {
23
24
        # array $high , array $low , array $close [, integer $timePeriod ]
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
25
        $cci = trader_cci($ohlcv->get('high'), $ohlcv->get('low'), $ohlcv->get('close'), $period);
26
27
        if (false === $cci) {
28
            throw new NotEnoughDataPointsException('Not enough data points');
29
        }
30
31
        $cci = array_pop($cci); #[count($cci) - 1];
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
32
33
        if ($cci > 100) {
34
            return static::SELL; // overbought
35
        } elseif ($cci < -100) {
36
            return static::BUY;  // underbought
37
        } else {
38
            return static::HOLD;
39
        }
40
    }
41
}
42