diff --git a/src/Profiler.php b/src/Profiler.php index f717949..ad05ac8 100644 --- a/src/Profiler.php +++ b/src/Profiler.php @@ -6,11 +6,6 @@ /* final */class Profiler implements ProfilerInterface { - /** - * @var Profile|null $parentProfile - */ - protected Profile|null $parentProfile = null; - public function profile(callable $callable): ProcessableProfileInterface & ProfileWithOutputInterface { $profiling = Profiling::start(); @@ -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 } } diff --git a/src/Profiling.php b/src/Profiling.php index 590f5bb..6664ab0 100644 --- a/src/Profiling.php +++ b/src/Profiling.php @@ -46,18 +46,20 @@ public static function createNestedProfiler(Profiling $profiling): ProfilerInter * @param Profile $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; } }; }