diff --git a/src/Adapter/Profiler/Profiler.php b/src/Adapter/Profiler/Profiler.php index dae0b7e4..52ba376c 100644 --- a/src/Adapter/Profiler/Profiler.php +++ b/src/Adapter/Profiler/Profiler.php @@ -6,15 +6,26 @@ use PhpDb\Adapter\Exception; use PhpDb\Adapter\Exception\InvalidArgumentException; +use PhpDb\Adapter\ParameterContainer; use PhpDb\Adapter\StatementContainerInterface; use function end; 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,18 +44,15 @@ public function profilerStart(string|StatementContainerInterface $target): Profi 'end' => null, '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; - } else { - throw new Exception\InvalidArgumentException( - __FUNCTION__ . ' takes either a StatementContainer or a string' - ); } $this->profiles[$this->currentIndex] = $profileInformation; @@ -70,13 +78,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;