Skip to content

Commit

Permalink
Remove $skipCollect from Debugger (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored Jan 15, 2025
1 parent 666d2f1 commit ace7cea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
29 changes: 11 additions & 18 deletions src/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
final class Debugger
{
private bool $skipCollect = false;

/**
* @psalm-var array<string, CollectorInterface>
*/
Expand Down Expand Up @@ -66,19 +64,16 @@ public function getId(): string

public function startup(object $event): void
{
$this->id = str_replace('.', '', uniqid('', true));
$this->skipCollect = false;

if ($event instanceof BeforeRequest && $this->isRequestIgnored($event->getRequest())) {
$this->skipCollect = true;
return;
}

if ($event instanceof ApplicationStartup && $this->isCommandIgnored($event->commandName)) {
$this->skipCollect = true;
return;
}

$this->id = str_replace('.', '', uniqid('', true));

foreach ($this->collectors as $collector) {
$collector->startup();
}
Expand All @@ -91,20 +86,18 @@ public function shutdown(): void
}

try {
if (!$this->skipCollect) {
$collectedData = array_map(
static fn (CollectorInterface $collector) => $collector->getCollected(),
$this->collectors
);
$collectedData = array_map(
static fn (CollectorInterface $collector) => $collector->getCollected(),
$this->collectors
);

/** @var array[] $data */
[$data, $objectsMap] = $this->dataNormalizer->prepareDataAndObjectsMap($collectedData, 30);
/** @var array[] $data */
[$data, $objectsMap] = $this->dataNormalizer->prepareDataAndObjectsMap($collectedData, 30);

/** @var array $summary */
$summary = $this->dataNormalizer->prepareData($this->collectSummaryData(), 30);
/** @var array $summary */
$summary = $this->dataNormalizer->prepareData($this->collectSummaryData(), 30);

$this->storage->write($this->getId(), $data, $objectsMap, $summary);
}
$this->storage->write($this->getId(), $data, $objectsMap, $summary);
} finally {
foreach ($this->collectors as $collector) {
$collector->shutdown();
Expand Down
15 changes: 11 additions & 4 deletions tests/Unit/DebuggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public function testStartupWithSkipCollect(): void
public function testIgnoreByHeader(): void
{
$collector = $this->getMockBuilder(CollectorInterface::class)->getMock();
$collector->expects($this->once())->method('shutdown');
$collector->expects($this->never())->method('startup');
$collector->expects($this->never())->method('shutdown');

$storage = $this->getMockBuilder(StorageInterface::class)->getMock();
$storage->expects($this->never())->method('write');

Expand All @@ -52,7 +54,9 @@ public function testIgnoreByHeader(): void
public function testIgnoreByEnv(): void
{
$collector = $this->getMockBuilder(CollectorInterface::class)->getMock();
$collector->expects($this->once())->method('shutdown');
$collector->expects($this->never())->method('startup');
$collector->expects($this->never())->method('shutdown');

$storage = $this->getMockBuilder(StorageInterface::class)->getMock();
$storage->expects($this->never())->method('write');

Expand Down Expand Up @@ -80,7 +84,9 @@ public function testShutdown(): void
public function testShutdownWithSkipRequestCollect(): void
{
$collector = $this->getMockBuilder(CollectorInterface::class)->getMock();
$collector->expects($this->once())->method('shutdown');
$collector->expects($this->never())->method('startup');
$collector->expects($this->never())->method('shutdown');

$storage = $this->getMockBuilder(StorageInterface::class)->getMock();
$storage->expects($this->never())->method('write');

Expand All @@ -94,7 +100,8 @@ public function testShutdownWithSkipCommandCollect(array $ignoredCommands, ?stri
{
$collector = $this->getMockBuilder(CollectorInterface::class)->getMock();
$collector->expects($this->never())->method('startup');
$collector->expects($this->once())->method('shutdown');
$collector->expects($this->never())->method('shutdown');

$storage = $this->getMockBuilder(StorageInterface::class)->getMock();
$storage->expects($this->never())->method('write');

Expand Down

0 comments on commit ace7cea

Please sign in to comment.