Skip to content

Commit fc978a0

Browse files
authored
Refactor summary data structure (#306)
1 parent eb01a60 commit fc978a0

23 files changed

Lines changed: 113 additions & 107 deletions

src/Collector/CollectorInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface CollectorInterface
1111
{
1212
/**
1313
* @return string Collector's name.
14+
* @psalm-return non-empty-string
1415
*/
1516
public function getName(): string;
1617

src/Collector/CollectorTrait.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Yiisoft\Yii\Debug\Collector;
66

7+
/**
8+
* @psalm-require-implements CollectorInterface
9+
*/
710
trait CollectorTrait
811
{
912
private bool $isActive = false;
@@ -19,6 +22,9 @@ public function shutdown(): void
1922
$this->isActive = false;
2023
}
2124

25+
/**
26+
* @psalm-return non-empty-string
27+
*/
2228
public function getName(): string
2329
{
2430
return self::class;

src/Collector/Console/CommandCollector.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,10 @@ public function getSummary(): array
118118
}
119119

120120
return [
121-
'command' => [
122-
'name' => $commandEvent['name'],
123-
'class' => $commandEvent['command'] instanceof Command ? $commandEvent['command']::class : null,
124-
'input' => $commandEvent['input'],
125-
'exitCode' => $commandEvent['exitCode'] ?? self::UNDEFINED_EXIT_CODE,
126-
],
121+
'name' => $commandEvent['name'],
122+
'class' => $commandEvent['command'] instanceof Command ? $commandEvent['command']::class : null,
123+
'input' => $commandEvent['input'],
124+
'exitCode' => $commandEvent['exitCode'] ?? self::UNDEFINED_EXIT_CODE,
127125
];
128126
}
129127

src/Collector/Console/ConsoleAppInfoCollector.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,15 @@ public function getSummary(): array
7474
return [];
7575
}
7676
return [
77-
'console' => [
78-
'php' => [
79-
'version' => PHP_VERSION,
80-
],
81-
'request' => [
82-
'startTime' => $this->requestProcessingTimeStarted,
83-
'processingTime' => $this->requestProcessingTimeStopped - $this->requestProcessingTimeStarted,
84-
],
85-
'memory' => [
86-
'peakUsage' => memory_get_peak_usage(),
87-
],
77+
'php' => [
78+
'version' => PHP_VERSION,
79+
],
80+
'request' => [
81+
'startTime' => $this->requestProcessingTimeStarted,
82+
'processingTime' => $this->requestProcessingTimeStopped - $this->requestProcessingTimeStarted,
83+
],
84+
'memory' => [
85+
'peakUsage' => memory_get_peak_usage(),
8886
],
8987
];
9088
}

src/Collector/EventCollector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Yiisoft\Yii\Console\Event\ApplicationStartup as ConsoleApplicationStartup;
99
use Yiisoft\Yii\Http\Event\ApplicationStartup as HttpApplicationStartup;
1010

11+
use function count;
12+
1113
final class EventCollector implements SummaryCollectorInterface
1214
{
1315
use CollectorTrait;
@@ -53,9 +55,7 @@ public function getSummary(): array
5355
return [];
5456
}
5557
return [
56-
'event' => [
57-
'total' => count($this->events),
58-
],
58+
'total' => count($this->events),
5959
];
6060
}
6161

src/Collector/ExceptionCollector.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ public function getSummary(): array
5252
if (!$this->isActive()) {
5353
return [];
5454
}
55+
if ($this->exception === null) {
56+
return [];
57+
}
5558
return [
56-
'exception' => $this->exception === null ? [] : [
57-
'class' => $this->exception::class,
58-
'message' => $this->exception->getMessage(),
59-
'file' => $this->exception->getFile(),
60-
'line' => $this->exception->getLine(),
61-
'code' => $this->exception->getCode(),
62-
],
59+
'class' => $this->exception::class,
60+
'message' => $this->exception->getMessage(),
61+
'file' => $this->exception->getFile(),
62+
'line' => $this->exception->getLine(),
63+
'code' => $this->exception->getCode(),
6364
];
6465
}
6566

src/Collector/HttpClientCollector.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,15 @@ public function getSummary(): array
8989
return [];
9090
}
9191
return [
92-
'http' => [
93-
'count' => array_sum(array_map(static fn (array $requests) => count($requests), $this->requests)),
94-
'totalTime' => array_sum(
95-
array_merge(
96-
...array_map(
97-
static fn (array $entry) => array_column($entry, 'totalTime'),
98-
array_values($this->requests)
99-
)
92+
'count' => array_sum(array_map(static fn (array $requests) => count($requests), $this->requests)),
93+
'totalTime' => array_sum(
94+
array_merge(
95+
...array_map(
96+
static fn (array $entry) => array_column($entry, 'totalTime'),
97+
array_values($this->requests)
10098
)
101-
),
102-
],
99+
)
100+
),
103101
];
104102
}
105103
}

src/Collector/LogCollector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Yiisoft\Yii\Debug\Collector;
66

7+
use function count;
8+
79
class LogCollector implements SummaryCollectorInterface
810
{
911
use CollectorTrait;
@@ -50,9 +52,7 @@ public function getSummary(): array
5052
return [];
5153
}
5254
return [
53-
'logger' => [
54-
'total' => count($this->messages),
55-
],
55+
'total' => count($this->messages),
5656
];
5757
}
5858
}

src/Collector/ServiceCollector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Yiisoft\Yii\Debug\Collector;
66

7+
use function count;
8+
79
final class ServiceCollector implements SummaryCollectorInterface
810
{
911
use CollectorTrait;
@@ -58,9 +60,7 @@ public function getSummary(): array
5860
return [];
5961
}
6062
return [
61-
'service' => [
62-
'total' => count($this->items),
63-
],
63+
'total' => count($this->items),
6464
];
6565
}
6666

src/Collector/Stream/FilesystemStreamCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function getSummary(): array
7878
return [];
7979
}
8080
return [
81-
'fs_stream' => array_merge(
81+
'streams' => array_merge(
8282
...array_map(
8383
fn (string $operation) => [$operation => count($this->operations[$operation])],
8484
array_keys($this->operations)

0 commit comments

Comments
 (0)