Conditions | 1 |
Paths | 1 |
Total Lines | 69 |
Lines | 0 |
Ratio | 0 % |
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 |
||
52 | public function testCountOccurred() |
||
53 | { |
||
54 | /** @var SnapshotService $service */ |
||
55 | $service = $this->container->get(SnapshotService::class); |
||
56 | /** @var IncidentSource $source */ |
||
57 | $source = $this->container->get(IncidentSource::class); |
||
58 | |||
59 | $snapshot = $this->makeSnapshot('custom error', 777); |
||
60 | |||
61 | //Create 2 incidents |
||
62 | $snapshotRecord = $this->handleSnapshot($snapshot, true); |
||
63 | $counters = $service->countOccurred($snapshotRecord, $source); |
||
64 | |||
65 | $this->assertEquals(1, $counters['daily']); |
||
66 | $this->assertEquals(1, $counters['weekly']); |
||
67 | $this->assertEquals(1, $counters['monthly']); |
||
68 | $this->assertEquals(1, $counters['yearly']); |
||
69 | |||
70 | $this->handleSnapshot($snapshot, true); |
||
71 | $counters = $service->countOccurred($snapshotRecord, $source); |
||
72 | |||
73 | $this->assertEquals(2, $counters['daily']); |
||
74 | $this->assertEquals(2, $counters['weekly']); |
||
75 | $this->assertEquals(2, $counters['monthly']); |
||
76 | $this->assertEquals(2, $counters['yearly']); |
||
77 | |||
78 | /** @var IncidentRecord $incident */ |
||
79 | $incident = $snapshotRecord->getIncidentsHistory()->getIterator()->current(); |
||
80 | |||
81 | //One of them occurred not in this day |
||
82 | $incident->time_created = (new \DateTime('now'))->sub(new \DateInterval('P2D')); |
||
83 | $incident->save(); |
||
84 | |||
85 | $counters = $service->countOccurred($snapshotRecord, $source); |
||
86 | $this->assertEquals(1, $counters['daily']); |
||
87 | $this->assertEquals(2, $counters['weekly']); |
||
88 | $this->assertEquals(2, $counters['monthly']); |
||
89 | $this->assertEquals(2, $counters['yearly']); |
||
90 | |||
91 | //One of them occurred not in this week |
||
92 | $incident->time_created = (new \DateTime('now'))->sub(new \DateInterval('P8D')); |
||
93 | $incident->save(); |
||
94 | |||
95 | $counters = $service->countOccurred($snapshotRecord, $source); |
||
96 | $this->assertEquals(1, $counters['daily']); |
||
97 | $this->assertEquals(1, $counters['weekly']); |
||
98 | $this->assertEquals(2, $counters['monthly']); |
||
99 | $this->assertEquals(2, $counters['yearly']); |
||
100 | |||
101 | //One of them occurred not in this month |
||
102 | $incident->time_created = (new \DateTime('now'))->sub(new \DateInterval('P2M')); |
||
103 | $incident->save(); |
||
104 | |||
105 | $counters = $service->countOccurred($snapshotRecord, $source); |
||
106 | $this->assertEquals(1, $counters['daily']); |
||
107 | $this->assertEquals(1, $counters['weekly']); |
||
108 | $this->assertEquals(1, $counters['monthly']); |
||
109 | $this->assertEquals(2, $counters['yearly']); |
||
110 | |||
111 | //One of them occurred not in this year |
||
112 | $incident->time_created = (new \DateTime('now'))->sub(new \DateInterval('P2Y')); |
||
113 | $incident->save(); |
||
114 | |||
115 | $counters = $service->countOccurred($snapshotRecord, $source); |
||
116 | $this->assertEquals(1, $counters['daily']); |
||
117 | $this->assertEquals(1, $counters['weekly']); |
||
118 | $this->assertEquals(1, $counters['monthly']); |
||
119 | $this->assertEquals(1, $counters['yearly']); |
||
120 | } |
||
121 | |||
163 | } |