| Conditions | 1 |
| Paths | 1 |
| Total Lines | 54 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 23 | public function testProcessEventsWithAssociatedIdentifiersWithinWindow(): void |
||
| 24 | { |
||
| 25 | // Mock data |
||
| 26 | $events = collect([ |
||
| 27 | (object)[ |
||
| 28 | 'id' => 1, |
||
| 29 | 'type' => 'tag', |
||
| 30 | 'identifier' => 'article_ID:7', |
||
| 31 | 'event_time' => Carbon::now()->subSeconds(10), |
||
| 32 | ], |
||
| 33 | ]); |
||
| 34 | |||
| 35 | $associations = collect([ |
||
| 36 | (object)[ |
||
| 37 | 'event_id' => 1, |
||
| 38 | 'associated_type' => 'tag', |
||
| 39 | 'associated_identifier' => 'plp:sport', |
||
| 40 | ], |
||
| 41 | ]); |
||
| 42 | |||
| 43 | // Mock DB queries |
||
| 44 | DB::shouldReceive('table->where->where->where->where->orderBy->limit->get') |
||
| 45 | ->andReturn($events) |
||
| 46 | ; |
||
| 47 | |||
| 48 | DB::shouldReceive('table->whereIn->get') |
||
| 49 | ->andReturn($associations) |
||
| 50 | ; |
||
| 51 | |||
| 52 | // Mock last invalidation times |
||
| 53 | DB::shouldReceive('select')->andReturn([ |
||
| 54 | (object)[ |
||
| 55 | 'identifier_type' => 'tag', |
||
| 56 | 'identifier' => 'article_ID:7', |
||
| 57 | 'last_invalidated' => Carbon::now()->subSeconds(40)->toDateTimeString(), |
||
| 58 | ], |
||
| 59 | (object)[ |
||
| 60 | 'identifier_type' => 'tag', |
||
| 61 | 'identifier' => 'plp:sport', |
||
| 62 | 'last_invalidated' => Carbon::now()->subSeconds(20)->toDateTimeString(), |
||
| 63 | ], |
||
| 64 | ]); |
||
| 65 | |||
| 66 | // Mock Cache |
||
| 67 | Cache::shouldReceive('tags->flush')->never(); |
||
| 68 | |||
| 69 | // Mock update or insert |
||
| 70 | DB::shouldReceive('table->updateOrInsert')->never(); |
||
| 71 | |||
| 72 | // Mock event update |
||
| 73 | DB::shouldReceive('table->whereIn->update')->once(); |
||
| 74 | |||
| 75 | // Run the command |
||
| 76 | $this->command->handle(); |
||
| 77 | |||
| 81 |