Skip to content

Commit b224451

Browse files
author
Ahmed Raafat
committed
Rename to to signify that is an internal id that you will not be able to see it again & to to signify that this is not meant to categorize anything
1 parent 7eccd04 commit b224451

File tree

5 files changed

+54
-81
lines changed

5 files changed

+54
-81
lines changed

src/Symfony/Component/Stopwatch/Section.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,23 @@ public function setId(string $id)
110110
*
111111
* @return StopwatchEvent The event
112112
*/
113-
public function startEvent(string $name, ?string $category)
113+
public function startEvent(string $internalId, ?string $label)
114114
{
115-
if (!isset($this->events[$name])) {
116-
$this->events[$name] = new StopwatchEvent($this->origin ?: microtime(true) * 1000, $category, $this->morePrecision, $name);
115+
if (!isset($this->events[$internalId])) {
116+
$this->events[$internalId] = new StopwatchEvent($this->origin ?: microtime(true) * 1000, $label, $this->morePrecision);
117117
}
118118

119-
return $this->events[$name]->start();
119+
return $this->events[$internalId]->start();
120120
}
121121

122122
/**
123123
* Checks if the event was started.
124124
*
125125
* @return bool
126126
*/
127-
public function isEventStarted(string $name)
127+
public function isEventStarted(string $internalId)
128128
{
129-
return isset($this->events[$name]) && $this->events[$name]->isStarted();
129+
return isset($this->events[$internalId]) && $this->events[$internalId]->isStarted();
130130
}
131131

132132
/**
@@ -136,13 +136,13 @@ public function isEventStarted(string $name)
136136
*
137137
* @throws \LogicException When the event has not been started
138138
*/
139-
public function stopEvent(string $name)
139+
public function stopEvent(string $internalId)
140140
{
141-
if (!isset($this->events[$name])) {
142-
throw new \LogicException(sprintf('Event "%s" is not started.', $name));
141+
if (!isset($this->events[$internalId])) {
142+
throw new \LogicException(sprintf('Event "%s" is not started.', $internalId));
143143
}
144144

145-
return $this->events[$name]->stop();
145+
return $this->events[$internalId]->stop();
146146
}
147147

148148
/**
@@ -152,9 +152,9 @@ public function stopEvent(string $name)
152152
*
153153
* @throws \LogicException When the event has not been started
154154
*/
155-
public function lap(string $name)
155+
public function lap(string $internalId)
156156
{
157-
return $this->stopEvent($name)->start();
157+
return $this->stopEvent($internalId)->start();
158158
}
159159

160160
/**
@@ -164,13 +164,13 @@ public function lap(string $name)
164164
*
165165
* @throws \LogicException When the event is not known
166166
*/
167-
public function getEvent(string $name)
167+
public function getEvent(string $internalId)
168168
{
169-
if (!isset($this->events[$name])) {
170-
throw new \LogicException(sprintf('Event "%s" is not known.', $name));
169+
if (!isset($this->events[$internalId])) {
170+
throw new \LogicException(sprintf('Event "%s" is not known.', $internalId));
171171
}
172172

173-
return $this->events[$name];
173+
return $this->events[$internalId];
174174
}
175175

176176
/**

src/Symfony/Component/Stopwatch/Stopwatch.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,49 +101,49 @@ public function stopSection(string $id)
101101
*
102102
* @return StopwatchEvent
103103
*/
104-
public function start(string $name, string $category = null)
104+
public function start(string $internalId, string $label = null)
105105
{
106-
return end($this->activeSections)->startEvent($name, $category);
106+
return end($this->activeSections)->startEvent($internalId, $label);
107107
}
108108

109109
/**
110110
* Checks if the event was started.
111111
*
112112
* @return bool
113113
*/
114-
public function isStarted(string $name)
114+
public function isStarted(string $internalId)
115115
{
116-
return end($this->activeSections)->isEventStarted($name);
116+
return end($this->activeSections)->isEventStarted($internalId);
117117
}
118118

119119
/**
120120
* Stops an event.
121121
*
122122
* @return StopwatchEvent
123123
*/
124-
public function stop(string $name)
124+
public function stop(string $internalId)
125125
{
126-
return end($this->activeSections)->stopEvent($name);
126+
return end($this->activeSections)->stopEvent($internalId);
127127
}
128128

129129
/**
130130
* Stops then restarts an event.
131131
*
132132
* @return StopwatchEvent
133133
*/
134-
public function lap(string $name)
134+
public function lap(string $internalId)
135135
{
136-
return end($this->activeSections)->stopEvent($name)->start();
136+
return end($this->activeSections)->stopEvent($internalId)->start();
137137
}
138138

139139
/**
140140
* Returns a specific event by name.
141141
*
142142
* @return StopwatchEvent
143143
*/
144-
public function getEvent(string $name)
144+
public function getEvent(string $internalId)
145145
{
146-
return end($this->activeSections)->getEvent($name);
146+
return end($this->activeSections)->getEvent($internalId);
147147
}
148148

149149
/**

src/Symfony/Component/Stopwatch/StopwatchEvent.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class StopwatchEvent
3131
/**
3232
* @var string
3333
*/
34-
private $category;
34+
private $label;
3535

3636
/**
3737
* @var bool
@@ -43,35 +43,28 @@ class StopwatchEvent
4343
*/
4444
private $started = [];
4545

46-
/**
47-
* @var string
48-
*/
49-
private $name;
50-
5146
/**
5247
* @param float $origin The origin time in milliseconds
53-
* @param string|null $category The event category or null to use the default
48+
* @param string|null $label The event label or null to use the default
5449
* @param bool $morePrecision If true, time is stored as float to keep the original microsecond precision
55-
* @param string|null $name The event name or null to define the name as default
5650
*
5751
* @throws \InvalidArgumentException When the raw time is not valid
5852
*/
59-
public function __construct(float $origin, string $category = null, bool $morePrecision = false, string $name = null)
53+
public function __construct(float $origin, string $label = null, bool $morePrecision = false)
6054
{
6155
$this->origin = $this->formatTime($origin);
62-
$this->category = \is_string($category) ? $category : 'default';
56+
$this->label = \is_string($label) ? $label : 'default';
6357
$this->morePrecision = $morePrecision;
64-
$this->name = $name ?? 'default';
6558
}
6659

6760
/**
68-
* Gets the category.
61+
* Gets the label.
6962
*
70-
* @return string The category
63+
* @return string The label
7164
*/
72-
public function getCategory()
65+
public function getLabel()
7366
{
74-
return $this->category;
67+
return $this->label;
7568
}
7669

7770
/**
@@ -243,19 +236,11 @@ private function formatTime(float $time): float
243236
return round($time, 1);
244237
}
245238

246-
/**
247-
* Gets the event name.
248-
*/
249-
public function getName(): string
250-
{
251-
return $this->name;
252-
}
253-
254239
/**
255240
* @return string
256241
*/
257242
public function __toString()
258243
{
259-
return sprintf('%s: %.2F MiB - %d ms', $this->getName(), $this->getMemory() / 1024 / 1024, $this->getDuration());
244+
return sprintf('%s: %.2F MiB - %d ms', $this->getLabel(), $this->getMemory() / 1024 / 1024, $this->getDuration());
260245
}
261246
}

src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public function testGetOrigin()
3131
$this->assertEquals(12, $event->getOrigin());
3232
}
3333

34-
public function testGetCategory()
34+
public function testGetLabel()
3535
{
3636
$event = new StopwatchEvent(microtime(true) * 1000);
37-
$this->assertEquals('default', $event->getCategory());
37+
$this->assertEquals('default', $event->getLabel());
3838

39-
$event = new StopwatchEvent(microtime(true) * 1000, 'cat');
40-
$this->assertEquals('cat', $event->getCategory());
39+
$event = new StopwatchEvent(microtime(true) * 1000, 'label');
40+
$this->assertEquals('label', $event->getLabel());
4141
}
4242

4343
public function testGetPeriods()
@@ -198,19 +198,7 @@ public function testHumanRepresentation()
198198
$event->stop();
199199
$this->assertEquals(1, preg_match('/default: [0-9\.]+ MiB - [0-9]+ ms/', (string) $event));
200200

201-
$event = new StopwatchEvent(microtime(true) * 1000, 'foo');
202-
$this->assertEquals('default: 0.00 MiB - 0 ms', (string) $event);
203-
204-
$event = new StopwatchEvent(microtime(true) * 1000, 'foo', false, 'name');
205-
$this->assertEquals('name: 0.00 MiB - 0 ms', (string) $event);
206-
}
207-
208-
public function testGetName()
209-
{
210-
$event = new StopwatchEvent(microtime(true) * 1000);
211-
$this->assertEquals('default', $event->getName());
212-
213-
$event = new StopwatchEvent(microtime(true) * 1000, 'cat', false, 'test');
214-
$this->assertEquals('test', $event->getName());
201+
$event = new StopwatchEvent(microtime(true) * 1000, 'label');
202+
$this->assertEquals('label: 0.00 MiB - 0 ms', (string) $event);
215203
}
216204
}

src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@ class StopwatchTest extends TestCase
2828
public function testStart()
2929
{
3030
$stopwatch = new Stopwatch();
31-
$event = $stopwatch->start('foo', 'cat');
31+
$event = $stopwatch->start('foo', 'label');
3232

3333
$this->assertInstanceOf('Symfony\Component\Stopwatch\StopwatchEvent', $event);
34-
$this->assertEquals('cat', $event->getCategory());
34+
$this->assertEquals('label', $event->getLabel());
3535
$this->assertSame($event, $stopwatch->getEvent('foo'));
3636
}
3737

38-
public function testStartWithoutCategory()
38+
public function testStartWithoutLabel()
3939
{
4040
$stopwatch = new Stopwatch();
4141
$stopwatchEvent = $stopwatch->start('bar');
42-
$this->assertSame('default', $stopwatchEvent->getCategory());
42+
$this->assertSame('default', $stopwatchEvent->getLabel());
4343
$this->assertSame($stopwatchEvent, $stopwatch->getEvent('bar'));
4444
}
4545

4646
public function testIsStarted()
4747
{
4848
$stopwatch = new Stopwatch();
49-
$stopwatch->start('foo', 'cat');
49+
$stopwatch->start('foo', 'label');
5050

5151
$this->assertTrue($stopwatch->isStarted('foo'));
5252
}
@@ -82,7 +82,7 @@ public function testIsNotStartedEvent()
8282
public function testStop()
8383
{
8484
$stopwatch = new Stopwatch();
85-
$stopwatch->start('foo', 'cat');
85+
$stopwatch->start('foo', 'label');
8686
usleep(200000);
8787
$event = $stopwatch->stop('foo');
8888

@@ -121,19 +121,19 @@ public function testSection()
121121
$stopwatch = new Stopwatch();
122122

123123
$stopwatch->openSection();
124-
$stopwatch->start('foo', 'cat');
124+
$stopwatch->start('foo', 'label');
125125
$stopwatch->stop('foo');
126-
$stopwatch->start('bar', 'cat');
126+
$stopwatch->start('bar', 'label');
127127
$stopwatch->stop('bar');
128128
$stopwatch->stopSection('1');
129129

130130
$stopwatch->openSection();
131-
$stopwatch->start('foobar', 'cat');
131+
$stopwatch->start('foobar', 'label');
132132
$stopwatch->stop('foobar');
133133
$stopwatch->stopSection('2');
134134

135135
$stopwatch->openSection();
136-
$stopwatch->start('foobar', 'cat');
136+
$stopwatch->start('foobar', 'label');
137137
$stopwatch->stop('foobar');
138138
$stopwatch->stopSection('0');
139139

@@ -148,11 +148,11 @@ public function testReopenASection()
148148
$stopwatch = new Stopwatch();
149149

150150
$stopwatch->openSection();
151-
$stopwatch->start('foo', 'cat');
151+
$stopwatch->start('foo', 'label');
152152
$stopwatch->stopSection('section');
153153

154154
$stopwatch->openSection('section');
155-
$stopwatch->start('bar', 'cat');
155+
$stopwatch->start('bar', 'label');
156156
$stopwatch->stopSection('section');
157157

158158
$events = $stopwatch->getSectionEvents('section');
@@ -173,7 +173,7 @@ public function testReset()
173173
$stopwatch = new Stopwatch();
174174

175175
$stopwatch->openSection();
176-
$stopwatch->start('foo', 'cat');
176+
$stopwatch->start('foo', 'label');
177177

178178
$stopwatch->reset();
179179

0 commit comments

Comments
 (0)