| Conditions | 7 |
| Paths | 7 |
| Total Lines | 44 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 56 |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function __invoke(Collection $ohlcv, bool $numperiods = false): int |
||
| 22 | { |
||
| 23 | |||
| 24 | $a_htm = trader_ht_trendmode($ohlcv->get('close')); |
||
| 25 | |||
| 26 | if (false === $a_htm) { |
||
| 27 | throw new NotEnoughDataPointsException('Not enough data points'); |
||
| 28 | } |
||
| 29 | |||
| 30 | |||
| 31 | if (!$a_htm) { |
||
| 32 | throw new \RuntimeException('Not enough data points. Maybe clear cache and start over.'); |
||
| 33 | } |
||
| 34 | |||
| 35 | $htm = array_pop($a_htm); |
||
| 36 | |||
| 37 | /** |
||
| 38 | * We can return the number of periods we have been |
||
| 39 | * in either a trend or a cycle by calling this again with |
||
| 40 | * $numperiods == true |
||
| 41 | */ |
||
| 42 | if ($numperiods) { |
||
| 43 | $nump = 1; |
||
| 44 | $test = $htm; |
||
|
|
|||
| 45 | for ($b = 0; $b < count($a_htm); $b++) { |
||
| 46 | $test = array_pop($a_htm); |
||
| 47 | if ($test == $htm) { |
||
| 48 | $nump++; |
||
| 49 | } else { |
||
| 50 | break; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | return $nump; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Otherwise we just return if we are in a trend or not. |
||
| 58 | */ |
||
| 59 | if ($htm == 1) { |
||
| 60 | return 1; // we are in a trending mode |
||
| 61 | } |
||
| 62 | |||
| 63 | return 0; // we are cycling. |
||
| 64 | } |
||
| 65 | |||
| 67 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.