Skip to content

Commit

Permalink
Merge pull request #6 from petrknap/chores
Browse files Browse the repository at this point in the history
Nested profiler logic fully moved to nested profiler
  • Loading branch information
petrknap authored Oct 12, 2024
2 parents a2bdd8c + 2286e8f commit 3ea8a5b
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 3ea8a5b

Please sign in to comment.