Skip to content

Commit 05e51c0

Browse files
committed
Fix Version
1 parent 819f802 commit 05e51c0

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/Profiler.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use IteratorAggregate;
1212
use JsonSerializable;
1313
use Psr\Log\LoggerInterface;
14+
use Psr\Log\NullLogger;
1415
use Throwable;
1516
use Traversable;
1617

@@ -33,22 +34,20 @@ final class Profiler implements JsonSerializable, IteratorAggregate, Countable
3334
/** @var non-empty-string */
3435
private readonly string $identifier;
3536
private readonly Closure $callback;
36-
private readonly ?LoggerInterface $logger;
3737
/** @var list<Span> */
3838
private array $spans;
3939

4040
/**
4141
* @param ?non-empty-string $identifier
4242
*/
43-
public function __construct(callable $callback, ?string $identifier = null, ?LoggerInterface $logger = null)
43+
public function __construct(callable $callback, ?string $identifier = null, private LoggerInterface $logger = new NullLogger())
4444
{
4545
$identifier ??= self::generateLabel();
4646
$identifier = trim($identifier);
4747
'' !== $identifier || throw new InvalidArgument('The identifier must be a non-empty string.');
4848

4949
$this->identifier = $identifier;
5050
$this->callback = $callback instanceof Closure ? $callback : $callback(...);
51-
$this->logger = $logger;
5251
$this->reset();
5352
}
5453

@@ -92,20 +91,20 @@ public function run(mixed ...$args): mixed
9291
public function profile(string $label, mixed ...$args): mixed
9392
{
9493
try {
95-
$this->logger?->info('Profiler ['.$this->identifier.'] starting profiling for label: '.$label.'.', ['identifier' => $this->identifier, 'label' => $label]);
94+
$this->logger->info('Profiler ['.$this->identifier.'] starting profiling for label: '.$label.'.', ['identifier' => $this->identifier, 'label' => $label]);
9695
$start = Snapshot::now('start');
9796
$returnValue = ($this->callback)(...$args);
9897
$end = Snapshot::now('end');
9998
$span = new Span($label, $start, $end);
100-
$this->logger?->info('Profiler ['.$this->identifier.'] ending profiling for label: '.$label.'.', [...['identifier' => $this->identifier], ...$span->toArray()]);
99+
$this->logger->info('Profiler ['.$this->identifier.'] ending profiling for label: '.$label.'.', [...['identifier' => $this->identifier], ...$span->toArray()]);
101100

102101
$profiled = new Result($returnValue, $span);
103102
$this->spans[] = $profiled->span;
104103

105104
return $profiled->returnValue;
106105

107106
} catch (Throwable $exception) {
108-
$this->logger?->error('Profiler ['.$this->identifier.'] profiling aborted for label: '.$label.' due to an error in the executed code.', ['identifier' => $this->identifier, 'label' => $label, 'exception' => $exception]);
107+
$this->logger->error('Profiler ['.$this->identifier.'] profiling aborted for label: '.$label.' due to an error in the executed code.', ['identifier' => $this->identifier, 'label' => $label, 'exception' => $exception]);
109108

110109
throw $exception;
111110
}

src/Timeline.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use IteratorAggregate;
1212
use JsonSerializable;
1313
use Psr\Log\LoggerInterface;
14+
use Psr\Log\NullLogger;
1415
use Traversable;
1516

1617
use function array_key_exists;
@@ -34,18 +35,18 @@ final class Timeline implements Countable, IteratorAggregate, JsonSerializable
3435
/** @var array<non-empty-string, Snapshot> */
3536
private array $snapshots;
3637
private bool $isComplete;
37-
private ?LoggerInterface $logger;
3838

3939
/**
4040
* @param ?non-empty-string $identifier
4141
*/
42-
public function __construct(?string $identifier = null, ?LoggerInterface $logger = null)
43-
{
42+
public function __construct(
43+
?string $identifier = null,
44+
private LoggerInterface $logger = new NullLogger()
45+
) {
4446
$identifier = trim($identifier ?? (new LabelGenerator())->generate());
4547
'' !== $identifier || throw new InvalidArgument('The identifier must be a non-empty string.');
4648

4749
$this->identifier = $identifier;
48-
$this->logger = $logger;
4950
$this->reset();
5051
}
5152

@@ -273,7 +274,7 @@ public function summarize(?string $label = null): Span
273274
* @param non-empty-string $label
274275
* @param ?non-empty-string $identifier
275276
*/
276-
public static function start(string $label = 'start', ?string $identifier = null, ?LoggerInterface $logger = null): self
277+
public static function start(string $label = 'start', ?string $identifier = null, LoggerInterface $logger = new NullLogger()): self
277278
{
278279
$timeline = new self($identifier, $logger);
279280
$timeline->capture($label);
@@ -330,7 +331,7 @@ public function dd(?callable $filter = null): never
330331
*/
331332
private function log(string $message, array $context = []): void
332333
{
333-
$this->logger?->info('Timeline ['.$this->identifier.'] '.$message, [
334+
$this->logger->info('Timeline ['.$this->identifier.'] '.$message, [
334335
'identifier' => $this->identifier,
335336
...$context,
336337
]);

src/Version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
final class Version implements Stringable
1212
{
1313
private const NAME = 'stackwatch';
14-
private const VERSION_ID = '0.15.0';
15-
private const VERSION_NAME = 'Ouagadougou';
14+
private const VERSION_ID = '0.16.0';
15+
private const VERSION_NAME = 'Pointe-Noire';
1616
private const AUTHOR = 'Ignace Nyamagana Butera';
1717

1818
public static function name(): string

0 commit comments

Comments
 (0)