Completed
Pull Request — master (#3)
by
unknown
01:16
created

MoneyFlowIndexIndicator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 28
loc 28
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 24 24 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
/**
11
 * Money Flow Index
12
 *
13
 * @see https://www.investopedia.com/terms/m/mfi.asp
14
 *
15
 * What is the 'Money Flow Index - MFI'
16
 * 
17
 * The money flow index (MFI) is a momentum indicator that measures the inflow and 
18
 * outflow of money into a security over a specific period of time. The MFI uses a 
19
 * stock's price and volume to measure trading pressure. Because the MFI adds trading 
20
 * volume to the relative strength index (RSI), it's sometimes referred to as volume-weighted RSI. 
21
 * 
22
 *
23
 */
24 View Code Duplication
class MoneyFlowIndexIndicator 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...
25
{
26
    public function __invoke(Collection $ohlcv, int $period = 14): int
27
    {
28
        $mfi = trader_mfi(
29
            $ohlcv->get('high'),
30
            $ohlcv->get('low'),
31
            $ohlcv->get('close'),
32
            $ohlcv->get('volume'),
33
            $period
34
        );
35
36
        if (false === $mfi) {
37
            throw new NotEnoughDataPointsException('Not enough data points');
38
        }
39
40
        $mfiValue = array_pop($mfi);
41
42
        if ($mfiValue < -10) {
43
            return static::BUY;
44
        } elseif ($mfiValue > 80) {
45
            return static::SELL;
46
        }
47
48
        return static::HOLD;
49
    }
50
51
}