Issues (13)

src/Strategy/StrategyCalculator.php (6 issues)

1
<?php
2
3
namespace Mokka\Strategy;
4
5
6
use DoctrineTest\InstantiatorTestAsset\AbstractClassAsset;
7
use Mokka\Action\Action;
8
use Mokka\Action\ActionInterface;
9
use Mokka\Action\BuyAction;
10
use Mokka\Action\IdleAction;
11
use Mokka\Action\SellAction;
12
use Mokka\Config\Logger;
13
use Mokka\Exchange\ExchangeInterface;
14
15
class StrategyCalculator
16
{
17
18
    /**
19
     * @var ExchangeInterface
20
     */
21
    private static $exchange;
22
    /**
23
     * @var IndicatorInterface
24
     */
25
    private static $indicator;
26
27
28
    /**
29
     * @var
30
     */
31
    private $symbol;
32
33
    /**
34
     * @var
35
     */
36
    private $interval;
37
38
    /**
39
     * @var
40
     */
41
    private $market;
42
    /**
43
     * StrategyCalculator constructor.
44
     * @param ExchangeInterface $exchange
45
     * @param IndicatorInterface $indicator
46
     */
47
    public function __construct(
48
        ExchangeInterface $exchange,
49
        IndicatorInterface $indicator
50
    )
51
    {
52
        self::$exchange = $exchange;
53
        self::$indicator = $indicator;
54
55
    }
56
57
    public function run(Logger $logger): Action
58
    {
59
        //get last action and price from logs
60
        $lastAction = $logger
0 ignored issues
show
Are you sure the assignment to $lastAction is correct as $logger->read()->where('...te')->limit(1)->first() targeting Flatbase\Query\ReadQuery::first() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
61
            ->read()
62
            ->where('market', '=', $this->getMarket())
63
            ->where('symbol', '=', $this->getSymbol())
64
            ->sortDesc('lastUpdate')
65
            ->limit(1)
66
            ->first();
67
68
        $lastAction = new Action($lastAction);
69
70
        //calculate in loop by interval
71
        /** @var ActionInterface $actionType */
72
        $actionType = self::$indicator->calculate($this->getSymbol(), $lastAction);
73
74
        if ($actionType->getType() == ActionInterface::TYPE_BUY) {
75
            $action = new BuyAction();
76
        }elseif ($actionType->getType() == ActionInterface::TYPE_SELL) {
77
            $action = new SellAction();
78
        }elseif ($actionType->getType() == ActionInterface::TYPE_IDLE) {
79
            $action = new IdleAction();
80
        }
81
82
        /** @var ActionInterface $action */
83
        $action->setType($actionType->getType());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $action does not seem to be defined for all execution paths leading up to this point.
Loading history...
84
        $action->setSymbol($this->getSymbol());
0 ignored issues
show
The method setSymbol() does not exist on Mokka\Action\ActionInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Mokka\Action\ActionInterface. ( Ignorable by Annotation )

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

84
        $action->/** @scrutinizer ignore-call */ 
85
                 setSymbol($this->getSymbol());
Loading history...
85
        $action->setMarket($this->getMarket());
0 ignored issues
show
The method setMarket() does not exist on Mokka\Action\ActionInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Mokka\Action\ActionInterface. ( Ignorable by Annotation )

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

85
        $action->/** @scrutinizer ignore-call */ 
86
                 setMarket($this->getMarket());
Loading history...
86
        $action->setPreviousPrice($lastAction->getActionPrice());
87
        $action->setActionPrice($actionType->getActionPrice());
88
        $action->setLastUpdate(time());
0 ignored issues
show
The method setLastUpdate() does not exist on Mokka\Action\ActionInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Mokka\Action\ActionInterface. ( Ignorable by Annotation )

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

88
        $action->/** @scrutinizer ignore-call */ 
89
                 setLastUpdate(time());
Loading history...
89
90
        return $action;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $action returns the type Mokka\Action\ActionInterface which is incompatible with the type-hinted return Mokka\Action\Action.
Loading history...
91
    }
92
93
    /**
94
     * @return mixed
95
     */
96
    public function getSymbol()
97
    {
98
        return $this->symbol;
99
    }
100
101
    /**
102
     * @param mixed $symbol
103
     */
104
    public function setSymbol($symbol)
105
    {
106
        $this->symbol = $symbol;
107
    }
108
109
    /**
110
     * @return mixed
111
     */
112
    public function getInterval()
113
    {
114
        return $this->interval;
115
    }
116
117
    /**
118
     * @param mixed $interval
119
     */
120
    public function setInterval($interval)
121
    {
122
        $this->interval = $interval;
123
    }
124
125
    /**
126
     * @return mixed
127
     */
128
    public function getMarket()
129
    {
130
        return $this->market;
131
    }
132
133
    /**
134
     * @param mixed $market
135
     */
136
    public function setMarket($market)
137
    {
138
        $this->market = $market;
139
    }
140
141
}