| Conditions | 5 | 
| Paths | 5 | 
| Total Lines | 35 | 
| Code Lines | 18 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 0 | 
| CRAP Score | 30 | 
| Changes | 0 | ||
| 1 | <?php  | 
            ||
| 22 | public function __invoke(Collection $ohlcv, bool $numPeriods = false): int  | 
            ||
| 23 |     { | 
            ||
| 24 | $htm = trader_ht_trendmode(  | 
            ||
| 25 |             $ohlcv->get('open'), | 
            ||
| 26 |             $ohlcv->get('close') | 
            ||
| 27 | );  | 
            ||
| 28 | |||
| 29 | throw_unless($htm, NotEnoughDataException::class);  | 
            ||
| 30 | |||
| 31 | $htmValue = array_pop($htm);  | 
            ||
| 32 | |||
| 33 | /**  | 
            ||
| 34 | * We can return the number of periods we have been  | 
            ||
| 35 | * in either a trend or a cycle by calling this again with  | 
            ||
| 36 | * $numperiods == true  | 
            ||
| 37 | */  | 
            ||
| 38 |         if ($numPeriods) { | 
            ||
| 39 | $nump = 1;  | 
            ||
| 40 | |||
| 41 |             for ($b = 0; $b < count($htm); $b++) { | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 42 | $test = array_pop($htm);  | 
            ||
| 43 |                 if ($test == $htmValue) { | 
            ||
| 44 | $nump++;  | 
            ||
| 45 |                 } else { | 
            ||
| 46 | break;  | 
            ||
| 47 | }  | 
            ||
| 48 | }  | 
            ||
| 49 | |||
| 50 | return $nump;  | 
            ||
| 51 |         } elseif ($htmValue == 1) { | 
            ||
| 52 | return static::BUY;  | 
            ||
| 53 | }  | 
            ||
| 54 | |||
| 55 | return static::HOLD;  | 
            ||
| 56 | }  | 
            ||
| 57 | }  | 
            ||
| 58 | 
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: