| Conditions | 14 |
| Paths | 6 |
| Total Lines | 35 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 210 |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 22 | public function __invoke(Collection $ohlcv, bool $trend = false): int |
||
| 23 | { |
||
| 24 | $hts = trader_ht_sine( |
||
| 25 | $ohlcv->get('open'), |
||
| 26 | $ohlcv->get('close') |
||
| 27 | ); |
||
| 28 | |||
| 29 | throw_unless($hts, NotEnoughDataException::class); |
||
| 30 | |||
| 31 | $dcsine = array_pop($hts[1]); |
||
| 32 | $p_dcsine = array_pop($hts[1]); |
||
| 33 | // leadsine is the first one it looks like. |
||
| 34 | $leadsine = array_pop($hts[0]); |
||
| 35 | $p_leadsine = array_pop($hts[0]); |
||
| 36 | |||
| 37 | if ($trend) { |
||
| 38 | if ($dcsine < 0 && $p_dcsine < 0 && $leadsine < 0 && $p_leadsine < 0) { |
||
| 39 | return static::BUY; // uptrend |
||
| 40 | } elseif ($dcsine > 0 && $p_dcsine > 0 && $leadsine > 0 && $p_leadsine > 0) { |
||
| 41 | return static::SELL; // downtrend |
||
| 42 | } |
||
| 43 | |||
| 44 | return static::HOLD; |
||
| 45 | } |
||
| 46 | |||
| 47 | /** WE ARE NOT ASKING FOR THE TREND, RETURN A SIGNAL */ |
||
| 48 | if ($leadsine > $dcsine && $p_leadsine <= $p_dcsine) { |
||
| 49 | return static::BUY; // buy |
||
| 50 | } |
||
| 51 | if ($leadsine < $dcsine && $p_leadsine >= $p_dcsine) { |
||
| 52 | return static::SELL; // sell |
||
| 53 | } |
||
| 54 | |||
| 55 | return static::HOLD; |
||
| 56 | } |
||
| 57 | } |
||
| 58 |