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

TradesCounter::countTrade()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 11
ccs 0
cts 6
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: alec
4
 * Date: 19.11.18
5
 * Time: 17:08
6
 */
7
8
namespace AlecRabbit;
9
10
use AlecRabbit\Event\EventCounterDeprecated;
11
use AlecRabbit\Structures\Trade;
12
13
class TradesCounter
14
{
15
    protected const VOLUME = 'volume';
16
17
    /** @var string */
18
    private $pair;
19
20
    /**@var EventCounterDeprecated[] */
21
    private $counters = [];
22
23
    /**
24
     * TradesCounter constructor.
25
     * @param string $pair
26
     */
27
    public function __construct(string $pair)
28
    {
29
        foreach (PERIODS as $length => $groupBy) {
30
            $this->counters[$length] = new EventCounterDeprecated($length, $groupBy);
31
        }
32
        $this->pair = $pair;
33
    }
34
35
    public function countTrade(Trade $trade): Trade
36
    {
37
        if ($this->pair !== $trade->pair) {
38
            throw new \RuntimeException('DataInconsistency'); // todo update message
39
        }
40
        foreach (PERIODS as $length => $groupBy) {
41
            $this->counters[$length]->addEvent($trade->timestamp);
42
        }
43
//        $this->counters[static::VOLUME]->addTrade($trade);
44
45
        return $trade;
46
    }
47
48
    public function trades(int $timePeriod): int
49
    {
50
        return $this->counters[$timePeriod]->getCalculatedEvents();
51
    }
52
53
    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

53
    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...
54
    {
55
        return 0.1;
56
    }
57
58
    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

58
    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...
59
    {
60
        return 8500;
61
    }
62
}
63