Skip to content

Commit

Permalink
refactor: nested profiler logic fully moved to nested profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
petrknap committed Oct 12, 2024
1 parent a2bdd8c commit 2286e8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
7 changes: 0 additions & 7 deletions src/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

/* final */class Profiler implements ProfilerInterface
{
/**
* @var Profile<mixed>|null $parentProfile
*/
protected Profile|null $parentProfile = null;

public function profile(callable $callable): ProcessableProfileInterface & ProfileWithOutputInterface
{
$profiling = Profiling::start();
Expand All @@ -19,8 +14,6 @@ public function profile(callable $callable): ProcessableProfileInterface & Profi
$profile = $profiling->finish();
$profile->setOutput($output);

$this->parentProfile?->addChild($profile);

return $profile; // @phpstan-ignore return.type
}
}
10 changes: 6 additions & 4 deletions src/Profiling.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,20 @@ public static function createNestedProfiler(Profiling $profiling): ProfilerInter
* @param Profile<mixed> $parentProfile
*/
public function __construct(
Profile $parentProfile,
private readonly Profile $parentProfile,
) {
$this->parentProfile = $parentProfile;
}

public function profile(callable $callable): ProcessableProfileInterface & ProfileWithOutputInterface
{
if ($this->parentProfile?->getState() !== ProfileState::Started) {
if ($this->parentProfile->getState() !== ProfileState::Started) {
throw new Exception\ParentProfileIsNotStarted();
}

return parent::profile($callable);
$profile = parent::profile($callable);
$this->parentProfile->addChild($profile);

return $profile;
}
};
}
Expand Down

0 comments on commit 2286e8f

Please sign in to comment.