From 144cf7eb96bea90b0b997e70628c1476810945c7 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Sat, 1 Jun 2024 00:28:54 +0400 Subject: [PATCH] chore: polishing --- src/Config/Server/Files/XHProf.php | 2 +- src/Proto/Frame/Profiler/Type.php | 1 + src/Service/Config/ConfigLoader.php | 5 ++++- .../{Filter => Converter}/XHProf.php | 20 +++++++++++-------- 4 files changed, 18 insertions(+), 10 deletions(-) rename src/Service/FilesObserver/{Filter => Converter}/XHProf.php (92%) diff --git a/src/Config/Server/Files/XHProf.php b/src/Config/Server/Files/XHProf.php index 83baa606..13a3bc22 100644 --- a/src/Config/Server/Files/XHProf.php +++ b/src/Config/Server/Files/XHProf.php @@ -5,7 +5,7 @@ namespace Buggregator\Trap\Config\Server\Files; use Buggregator\Trap\Service\Config\PhpIni; -use Buggregator\Trap\Service\FilesObserver\Filter\XHProf as Converter; +use Buggregator\Trap\Service\FilesObserver\Converter\XHProf as Converter; /** * @internal diff --git a/src/Proto/Frame/Profiler/Type.php b/src/Proto/Frame/Profiler/Type.php index 3b445d2e..6e95a466 100644 --- a/src/Proto/Frame/Profiler/Type.php +++ b/src/Proto/Frame/Profiler/Type.php @@ -12,4 +12,5 @@ enum Type: string { case XHProf = 'XHProf'; case XDebug = 'XDebug'; + case SPX = 'SPX'; } diff --git a/src/Service/Config/ConfigLoader.php b/src/Service/Config/ConfigLoader.php index 6a4b2d76..f1cdb8f5 100644 --- a/src/Service/Config/ConfigLoader.php +++ b/src/Service/Config/ConfigLoader.php @@ -59,7 +59,10 @@ private function injectValue(object $config, \ReflectionProperty $property, arra /** @var mixed $value */ $value = match (true) { - $attribute instanceof XPath => @$this->xml?->xpath($attribute->path)[$attribute->key], + $attribute instanceof XPath => (static fn(?array $value, int $key): mixed => match (true) { + \array_key_exists($key, $value) => $value[$key], + default => null, + })($this->xml?->xpath($attribute->path), $attribute->key), $attribute instanceof Env => $this->env[$attribute->name] ?? null, $attribute instanceof InputOption => $this->inputOptions[$attribute->name] ?? null, $attribute instanceof InputArgument => $this->inputArguments[$attribute->name] ?? null, diff --git a/src/Service/FilesObserver/Filter/XHProf.php b/src/Service/FilesObserver/Converter/XHProf.php similarity index 92% rename from src/Service/FilesObserver/Filter/XHProf.php rename to src/Service/FilesObserver/Converter/XHProf.php index 02cfde68..9c1abbc5 100644 --- a/src/Service/FilesObserver/Filter/XHProf.php +++ b/src/Service/FilesObserver/Converter/XHProf.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace Buggregator\Trap\Service\FilesObserver\Filter; +namespace Buggregator\Trap\Service\FilesObserver\Converter; +use Buggregator\Trap\Logger; use Buggregator\Trap\Proto\Frame\Profiler as ProfilerFrame; use Buggregator\Trap\Service\FilesObserver\FileInfo; use Buggregator\Trap\Service\FilesObserver\FrameConverter as FileFilterInterface; @@ -13,6 +14,10 @@ */ final class XHProf implements FileFilterInterface { + public function __construct( + private readonly Logger $logger, + ) {} + public function validate(FileInfo $file): bool { return $file->getExtension() === 'xhprof'; @@ -40,8 +45,7 @@ public function convert(FileInfo $file): \Traversable ), ); } catch (\Throwable $e) { - // todo log - \var_dump($e->getMessage()); + $this->logger->exception($e); } } @@ -76,11 +80,11 @@ private function dataToPayload(array $data): array 'callee' => $callee, 'caller' => $caller, 'cost' => [ - 'cpu' => (int) $value['cpu'], - 'ct' => (int) $value['ct'], - 'mu' => (int) $value['mu'], - 'pmu' => (int) $value['pmu'], - 'wt' => (int) $value['wt'], + 'cpu' => (int)$value['cpu'], + 'ct' => (int)$value['ct'], + 'mu' => (int)$value['mu'], + 'pmu' => (int)$value['pmu'], + 'wt' => (int)$value['wt'], ], ];