| Conditions | 1 |
| Paths | 1 |
| Total Lines | 67 |
| Code Lines | 45 |
| 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 |
||
| 19 | public function testDiffForHumansLocalizedInFarsi() |
||
| 20 | { |
||
| 21 | Date::setLocale('fa'); |
||
| 22 | |||
| 23 | $scope = $this; |
||
| 24 | $this->wrapWithTestNow( |
||
| 25 | function () use ($scope) { |
||
| 26 | $d = Date::now()->subSecond(); |
||
| 27 | $scope->assertSame('1 ثانیه پیش', $d->diffForHumans()); |
||
| 28 | |||
| 29 | $d = Date::now()->subSeconds(2); |
||
| 30 | $scope->assertSame('2 ثانیه پیش', $d->diffForHumans()); |
||
| 31 | |||
| 32 | $d = Date::now()->subMinute(); |
||
| 33 | $scope->assertSame('1 دقیقه پیش', $d->diffForHumans()); |
||
| 34 | |||
| 35 | $d = Date::now()->subMinutes(2); |
||
| 36 | $scope->assertSame('2 دقیقه پیش', $d->diffForHumans()); |
||
| 37 | |||
| 38 | $d = Date::now()->subHour(); |
||
| 39 | $scope->assertSame('1 ساعت پیش', $d->diffForHumans()); |
||
| 40 | |||
| 41 | $d = Date::now()->subHours(2); |
||
| 42 | $scope->assertSame('2 ساعت پیش', $d->diffForHumans()); |
||
| 43 | |||
| 44 | $d = Date::now()->subDay(); |
||
| 45 | $scope->assertSame('1 روز پیش', $d->diffForHumans()); |
||
| 46 | |||
| 47 | $d = Date::now()->subDays(2); |
||
| 48 | $scope->assertSame('2 روز پیش', $d->diffForHumans()); |
||
| 49 | |||
| 50 | $d = Date::now()->subWeek(); |
||
| 51 | $scope->assertSame('1 هفته پیش', $d->diffForHumans()); |
||
| 52 | |||
| 53 | $d = Date::now()->subWeeks(2); |
||
| 54 | $scope->assertSame('2 هفته پیش', $d->diffForHumans()); |
||
| 55 | |||
| 56 | $d = Date::now()->subMonth(); |
||
| 57 | $scope->assertSame('1 ماه پیش', $d->diffForHumans()); |
||
| 58 | |||
| 59 | $d = Date::now()->subMonths(2); |
||
| 60 | $scope->assertSame('2 ماه پیش', $d->diffForHumans()); |
||
| 61 | |||
| 62 | $d = Date::now()->subYear(); |
||
| 63 | $scope->assertSame('1 سال پیش', $d->diffForHumans()); |
||
| 64 | |||
| 65 | $d = Date::now()->subYears(2); |
||
| 66 | $scope->assertSame('2 سال پیش', $d->diffForHumans()); |
||
| 67 | |||
| 68 | $d = Date::now()->addSecond(); |
||
| 69 | $scope->assertSame('1 ثانیه بعد', $d->diffForHumans()); |
||
| 70 | |||
| 71 | $d = Date::now()->addSecond(); |
||
| 72 | $d2 = Date::now(); |
||
| 73 | $scope->assertSame('1 ثانیه پیش از', $d->diffForHumans($d2)); |
||
| 74 | $scope->assertSame('1 ثانیه پس از', $d2->diffForHumans($d)); |
||
| 75 | |||
| 76 | $d = Date::now()->addSecond(); |
||
| 77 | $d2 = Date::now(); |
||
| 78 | $scope->assertSame('1 ثانیه پیش از', $d->diffForHumans($d2)); |
||
| 79 | $scope->assertSame('1 ثانیه پس از', $d2->diffForHumans($d)); |
||
| 80 | |||
| 81 | $scope->assertSame('1 ثانیه', $d->diffForHumans($d2, true)); |
||
| 82 | $scope->assertSame('2 ثانیه', $d2->diffForHumans($d->addSecond(), true)); |
||
| 83 | } |
||
| 84 | ); |
||
| 85 | } |
||
| 86 | } |
||
| 87 |