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

TradesCounter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 48
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A trades() 0 3 1
A volume() 0 3 1
A countTrade() 0 11 3
A __construct() 0 6 2
A avgPrice() 0 3 1
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