MoneyFlowIndexIndicator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 35
loc 35
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 22 22 3

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\NotEnoughDataException;
8
use Throwable;
9
10 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...
11
{
12
    /**
13
     * Invoke the indicator.
14
     *
15
     * @param Collection $ohlcv
16
     * @param int        $timePeriod
17
     *
18
     * @return int
19
     *
20
     * @throws Throwable
21
     */
22
    public function __invoke(Collection $ohlcv, int $timePeriod = 14): int
23
    {
24
        $mfi = trader_mfi(
25
            $ohlcv->get('high'),
26
            $ohlcv->get('low'),
27
            $ohlcv->get('close'),
28
            $ohlcv->get('volume'),
29
            $timePeriod
30
        );
31
32
        throw_unless($mfi, NotEnoughDataException::class);
33
34
        $mfiValue = array_pop($mfi);
35
36
        if ($mfiValue < -10) {
37
            return static::BUY;
38
        } elseif ($mfiValue > 80) {
39
            return static::SELL;
40
        }
41
42
        return static::HOLD;
43
    }
44
}
45