Passed
Push — master ( 25257e...5200e3 )
by Alec
04:00
created

TradesAggregator::avgPrice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: alec
4
 * Date: 05.11.18
5
 * Time: 17:05
6
 */
7
declare(strict_types=1);
8
9
namespace AlecRabbit;
10
11
use AlecRabbit\Event\EventCounterDeprecated;
12
use AlecRabbit\Structures\Trade;
13
14
class TradesAggregator
15
{
16
    private const PERIODS = [
17
        P_01MIN => P_01MIN,
18
        P_03MIN => P_01MIN,
19
        P_05MIN => P_01MIN,
20
        P_15MIN => P_05MIN,
21
        P_30MIN => P_05MIN,
22
        P_45MIN => P_05MIN,
23
        P_01HOUR => P_15MIN,
24
        P_02HOUR => P_15MIN,
25
        P_03HOUR => P_15MIN,
26
        P_04HOUR => P_15MIN,
27
        P_01DAY => P_01HOUR,
28
    ];
29
30
    /** @var string */
31
    private $pair;
32
33
    /**@var EventCounterDeprecated[] */
34
    private $counters = [];
35
36
    /**
37
     * TradesCounter constructor.
38
     * @param string $pair
39
     */
40 15
    public function __construct(string $pair)
41
    {
42 15
        foreach (static::PERIODS as $length => $groupBy) {
43 15
            $this->counters[$length] = new EventCounterDeprecated($length, $groupBy);
44
        }
45 15
        $this->pair = $pair;
46 15
    }
47
48 14
    public function countTrade(Trade $trade): Trade
49
    {
50 14
        if ($this->pair !== $trade->pair) {
51
            throw new \RuntimeException('DataInconsistency'); // todo update message
52
        }
53 14
        foreach (static::PERIODS as $length => $groupBy) {
54 14
            $this->counters[$length]->addEvent($trade->timestamp);
55
        }
56 14
        return $trade;
57
    }
58
59 1
    public function trades(int $timePeriod): int
60
    {
61 1
        return $this->counters[$timePeriod]->getCalculatedEvents();
62
    }
63
64 1
    public function volume(int $timePeriod): float
0 ignored issues
show
Unused Code introduced by
The parameter $timePeriod is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

64
    public function volume(/** @scrutinizer ignore-unused */ int $timePeriod): float

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
    {
66 1
        return 0.1;
67
    }
68
69 1
    public function avgPrice(int $timePeriod): float
0 ignored issues
show
Unused Code introduced by
The parameter $timePeriod is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

69
    public function avgPrice(/** @scrutinizer ignore-unused */ int $timePeriod): float

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
    {
71 1
        return 8500;
72
    }
73
}
74