From 593541cea327993ccdf5769f74328ed44fceed2f Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Fri, 27 Mar 2026 18:29:41 -0500 Subject: [PATCH 1/3] Adds two phpstan types to cover the shape of $profile and $profiles. Removes a dead elseif branch from profilerStart since the parameter type is now constrained to string|StatementContainerInterface the removed elseif could never be reached. Signed-off-by: Joey Smith --- src/Adapter/Profiler/Profiler.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Adapter/Profiler/Profiler.php b/src/Adapter/Profiler/Profiler.php index dae0b7e4..d50db0ea 100644 --- a/src/Adapter/Profiler/Profiler.php +++ b/src/Adapter/Profiler/Profiler.php @@ -12,9 +12,19 @@ use function is_string; use function microtime; +/** + * @phpstan-type ProfileShape array{ + * sql: string, + * parameters: ParameterContainer|null, + * start: float, + * end: float|null, + * elapse: float|null, + * } + * @phpstan-type ProfilesShape ProfileShape[] + */ class Profiler implements ProfilerInterface { - /** @var array */ + /** @var ProfilesShape */ protected $profiles = []; /** @var int */ @@ -33,6 +43,7 @@ public function profilerStart(string|StatementContainerInterface $target): Profi 'end' => null, 'elapse' => null, ]; + if ($target instanceof StatementContainerInterface) { $profileInformation['sql'] = $target->getSql(); $container = $target->getParameterContainer(); @@ -41,10 +52,6 @@ public function profilerStart(string|StatementContainerInterface $target): Profi } } elseif (is_string($target)) { $profileInformation['sql'] = $target; - } else { - throw new Exception\InvalidArgumentException( - __FUNCTION__ . ' takes either a StatementContainer or a string' - ); } $this->profiles[$this->currentIndex] = $profileInformation; @@ -70,13 +77,16 @@ public function profilerFinish(): ProfilerInterface } /** - * @return array|null + * @return ProfileShape|null */ public function getLastProfile(): ?array { return end($this->profiles); } + /** + * @return ProfilesShape + */ public function getProfiles(): array { return $this->profiles; From 6562496fd37f99a99df71fd3259aa3f312900998 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Fri, 27 Mar 2026 18:54:23 -0500 Subject: [PATCH 2/3] Add missing use for ParameterContainer Signed-off-by: Joey Smith --- src/Adapter/Profiler/Profiler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Adapter/Profiler/Profiler.php b/src/Adapter/Profiler/Profiler.php index d50db0ea..0b1fe5bd 100644 --- a/src/Adapter/Profiler/Profiler.php +++ b/src/Adapter/Profiler/Profiler.php @@ -6,6 +6,7 @@ use PhpDb\Adapter\Exception; use PhpDb\Adapter\Exception\InvalidArgumentException; +use PhpDb\Adapter\ParameterContainer; use PhpDb\Adapter\StatementContainerInterface; use function end; From e52bd6d38adad69978a38cd963a55f7939587df4 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Fri, 27 Mar 2026 20:15:18 -0500 Subject: [PATCH 3/3] Flips those since is_string should be faster than instanceof Signed-off-by: Joey Smith --- src/Adapter/Profiler/Profiler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Adapter/Profiler/Profiler.php b/src/Adapter/Profiler/Profiler.php index 0b1fe5bd..52ba376c 100644 --- a/src/Adapter/Profiler/Profiler.php +++ b/src/Adapter/Profiler/Profiler.php @@ -45,14 +45,14 @@ public function profilerStart(string|StatementContainerInterface $target): Profi 'elapse' => null, ]; - if ($target instanceof StatementContainerInterface) { + if (is_string($target)) { + $profileInformation['sql'] = $target; + } else { $profileInformation['sql'] = $target->getSql(); $container = $target->getParameterContainer(); if ($container !== null) { $profileInformation['parameters'] = clone $container; } - } elseif (is_string($target)) { - $profileInformation['sql'] = $target; } $this->profiles[$this->currentIndex] = $profileInformation;