From 23edf6a6f3dc9e6fe2bce9f8680dcf328802f459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 9 May 2026 02:03:40 +0300 Subject: [PATCH 1/2] Extract getServer method Move allowed server keys to property --- src/ProfilingData.php | 52 +++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/ProfilingData.php b/src/ProfilingData.php index 6b44928..3159e93 100644 --- a/src/ProfilingData.php +++ b/src/ProfilingData.php @@ -7,6 +7,26 @@ */ final class ProfilingData { + /** @var array */ + private $allowedServerKeys = array( + 'DOCUMENT_ROOT', + 'HTTPS', + 'HTTP_HOST', + 'HTTP_USER_AGENT', + 'PATH_INFO', + 'PHP_AUTH_USER', + 'PHP_SELF', + 'QUERY_STRING', + 'REMOTE_ADDR', + 'REMOTE_USER', + 'REQUEST_METHOD', + 'REQUEST_TIME', + 'REQUEST_TIME_FLOAT', + 'SERVER_ADDR', + 'SERVER_NAME', + 'UNIQUE_ID', + ); + /** @var array */ private $excludeEnv; /** @var callable|null */ @@ -35,32 +55,11 @@ public function getProfilingData(array $profile) $sec = $requestTimeFloat[0]; $usec = isset($requestTimeFloat[1]) ? $requestTimeFloat[1] : 0; - $allowedServerKeys = array( - 'DOCUMENT_ROOT', - 'HTTPS', - 'HTTP_HOST', - 'HTTP_USER_AGENT', - 'PATH_INFO', - 'PHP_AUTH_USER', - 'PHP_SELF', - 'QUERY_STRING', - 'REMOTE_ADDR', - 'REMOTE_USER', - 'REQUEST_METHOD', - 'REQUEST_TIME', - 'REQUEST_TIME_FLOAT', - 'SERVER_ADDR', - 'SERVER_NAME', - 'UNIQUE_ID', - ); - - $serverMeta = array_intersect_key($_SERVER, array_flip($allowedServerKeys)); - $meta = array( 'url' => $url, 'get' => $_GET, 'env' => $this->getEnvironment($_ENV), - 'SERVER' => $serverMeta, + 'SERVER' => $this->getServer($_SERVER), 'simple_url' => $this->getSimpleUrl($url), 'request_ts_micro' => array('sec' => $sec, 'usec' => $usec), // these are superfluous and should be dropped in the future @@ -128,4 +127,13 @@ private function getUrl() return $url; } + + /** + * @param array $server + * @return array + */ + private function getServer(array $server) + { + return array_intersect_key($server, array_flip($this->allowedServerKeys)); + } } From 18d2b45d5f62bd2f6b849643081d5af969056351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 9 May 2026 02:23:43 +0300 Subject: [PATCH 2/2] Extract getRequestTime method --- src/ProfilingData.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ProfilingData.php b/src/ProfilingData.php index 3159e93..798af8f 100644 --- a/src/ProfilingData.php +++ b/src/ProfilingData.php @@ -51,9 +51,7 @@ public function getProfilingData(array $profile) { $url = $this->getUrl(); - $requestTimeFloat = explode('.', sprintf('%.6F', $_SERVER['REQUEST_TIME_FLOAT'])); - $sec = $requestTimeFloat[0]; - $usec = isset($requestTimeFloat[1]) ? $requestTimeFloat[1] : 0; + list($sec, $usec) = $this->getRequestTime($_SERVER['REQUEST_TIME_FLOAT']); $meta = array( 'url' => $url, @@ -128,6 +126,20 @@ private function getUrl() return $url; } + /** + * @param float $requestTime + * @return array + */ + private function getRequestTime($requestTime) + { + $parts = explode('.', sprintf('%.6F', $requestTime)); + + $sec = $parts[0]; + $usec = isset($parts[1]) ? $parts[1] : 0; + + return array((int)$sec, (int)$usec); + } + /** * @param array $server * @return array