Completed
Branch master (5a7b19)
by Evgenii
02:31
created

__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 13

Duplication

Lines 21
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 21
loc 21
ccs 0
cts 13
cp 0
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 13
nc 3
nop 2
crap 12
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 AverageDirectionalMovementIndexIndicator 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
        $adx = trader_adx(
25
            $ohlcv->get('high'),
26
            $ohlcv->get('low'),
27
            $ohlcv->get('close'),
28
            $timePeriod
29
        );
30
31
        throw_unless($adx, NotEnoughDataException::class);
32
33
        $adxValue = array_pop($adx);
34
35
        if ($adxValue > 50) {
36
            return static::BUY;
37
        } elseif ($adxValue < 20) {
38
            return static::SELL;
39
        }
40
41
        return static::HOLD;
42
    }
43
}
44