|
4 | 4 |
|
5 | 5 | namespace flight\apm\presenter; |
6 | 6 |
|
7 | | -trait PresenterCommonTrait |
8 | | -{ |
9 | | - /** |
10 | | - * Calculate percentile from an array of values |
| 7 | +trait PresenterCommonTrait { |
| 8 | + /** |
| 9 | + * Calculate percentile from an array of values |
11 | 10 | * |
12 | 11 | * @param array $data - The array of values |
13 | 12 | * @param int $percentile - The percentile to calculate |
14 | 13 | * @return float |
15 | | - */ |
16 | | - protected function calculatePercentile(array $data, int $percentile): float |
17 | | - { |
18 | | - if (empty($data)) return 0; |
19 | | - sort($data); |
20 | | - $index = ($percentile / 100) * (count($data) - 1); |
21 | | - $lower = floor($index); |
22 | | - $upper = ceil($index); |
23 | | - if ($lower == $upper) return $data[$lower]; |
24 | | - $fraction = $index - $lower; |
25 | | - return $data[$lower] + $fraction * ($data[$upper] - $data[$lower]); |
26 | | - } |
| 14 | + */ |
| 15 | + protected function calculatePercentile(array $data, int $percentile): float { |
| 16 | + if (empty($data)) return 0; |
| 17 | + sort($data); |
| 18 | + $index = ($percentile / 100) * (count($data) - 1); |
| 19 | + $lower = floor($index); |
| 20 | + $upper = ceil($index); |
| 21 | + if ($lower == $upper) return $data[$lower]; |
| 22 | + $fraction = $index - $lower; |
| 23 | + return $data[$lower] + $fraction * ($data[$upper] - $data[$lower]); |
| 24 | + } |
27 | 25 |
|
28 | | - /** |
29 | | - * Check if the database has JSON functions |
| 26 | + /** |
| 27 | + * Check if the database has JSON functions |
30 | 28 | * |
31 | 29 | * @return bool |
32 | | - */ |
33 | | - protected function databaseSupportsJson(): bool |
34 | | - { |
35 | | - try { |
36 | | - $this->db->query("SELECT json_extract('', '$')"); |
37 | | - return true; |
38 | | - } catch (\Exception $e) { |
39 | | - return false; |
40 | | - } |
41 | | - } |
| 30 | + */ |
| 31 | + protected function databaseSupportsJson(): bool { |
| 32 | + try { |
| 33 | + $this->pdoWrapper->query("SELECT json_extract('', '$')"); |
| 34 | + return true; |
| 35 | + } catch (\Exception $e) { |
| 36 | + return false; |
| 37 | + } |
| 38 | + } |
42 | 39 |
|
43 | | - /** |
44 | | - * Check if IP addresses should be masked |
| 40 | + /** |
| 41 | + * Check if IP addresses should be masked |
45 | 42 | * |
46 | 43 | * @return bool |
47 | | - */ |
48 | | - protected function shouldMaskIpAddresses(): bool |
49 | | - { |
50 | | - return $this->config['apm']['mask_ip_addresses'] ?? false; |
51 | | - } |
| 44 | + */ |
| 45 | + protected function shouldMaskIpAddresses(): bool { |
| 46 | + return $this->config['apm']['mask_ip_addresses'] ?? false; |
| 47 | + } |
52 | 48 |
|
53 | | - /** |
54 | | - * Mask an IP address |
| 49 | + /** |
| 50 | + * Mask an IP address |
55 | 51 | * |
56 | 52 | * @param string $ip - The IP address to mask |
57 | 53 | * @return string - The masked IP address |
58 | | - */ |
59 | | - protected function maskIpAddress(string $ip): string |
60 | | - { |
61 | | - $ipCharacter = strpos($ip, '.') !== false ? '.' : ':'; |
62 | | - $parts = explode($ipCharacter, $ip); |
63 | | - if (count($parts) === 4) { |
64 | | - $parts[3] = str_repeat('x', strlen($parts[3])); |
65 | | - } |
66 | | - if (count($parts) > 4) { |
67 | | - $parts[count($parts) - 1] = str_repeat('x', strlen($parts[count($parts) - 1])); |
68 | | - } |
69 | | - return implode('.', $parts); |
70 | | - } |
| 54 | + */ |
| 55 | + protected function maskIpAddress(string $ip): string { |
| 56 | + $ipCharacter = strpos($ip, '.') !== false ? '.' : ':'; |
| 57 | + $parts = explode($ipCharacter, $ip); |
| 58 | + if (count($parts) === 4) { |
| 59 | + $parts[3] = str_repeat('x', strlen($parts[3])); |
| 60 | + } |
| 61 | + if (count($parts) > 4) { |
| 62 | + $parts[count($parts) - 1] = str_repeat('x', strlen($parts[count($parts) - 1])); |
| 63 | + } |
| 64 | + return implode('.', $parts); |
| 65 | + } |
71 | 66 |
|
72 | | - /** |
73 | | - * Get operator options for event value filtering |
| 67 | + /** |
| 68 | + * Get operator options for event value filtering |
74 | 69 | * |
75 | 70 | * @return array<int, array<string, string>> |
76 | | - */ |
77 | | - public function getEventValueOperators(): array |
78 | | - { |
79 | | - return [ |
80 | | - ['id' => 'contains', 'name' => 'Contains', 'desc' => 'Value contains the text (case-insensitive)'], |
81 | | - ['id' => 'exact', 'name' => 'Equals', 'desc' => 'Value exactly matches the text'], |
82 | | - ['id' => 'starts_with', 'name' => 'Starts with', 'desc' => 'Value starts with the text'], |
83 | | - ['id' => 'ends_with', 'name' => 'Ends with', 'desc' => 'Value ends with the text'], |
84 | | - ['id' => 'greater_than', 'name' => '>', 'desc' => 'Value is greater than (numeric comparison)'], |
85 | | - ['id' => 'less_than', 'name' => '<', 'desc' => 'Value is less than (numeric comparison)'], |
86 | | - ['id' => 'greater_than_equal', 'name' => '>=', 'desc' => 'Value is greater than or equal to (numeric comparison)'], |
87 | | - ['id' => 'less_than_equal', 'name' => '<=', 'desc' => 'Value is less than or equal to (numeric comparison)'], |
88 | | - ]; |
89 | | - } |
| 71 | + */ |
| 72 | + public function getEventValueOperators(): array { |
| 73 | + return [ |
| 74 | + ['id' => 'contains', 'name' => 'Contains', 'desc' => 'Value contains the text (case-insensitive)'], |
| 75 | + ['id' => 'exact', 'name' => 'Equals', 'desc' => 'Value exactly matches the text'], |
| 76 | + ['id' => 'starts_with', 'name' => 'Starts with', 'desc' => 'Value starts with the text'], |
| 77 | + ['id' => 'ends_with', 'name' => 'Ends with', 'desc' => 'Value ends with the text'], |
| 78 | + ['id' => 'greater_than', 'name' => '>', 'desc' => 'Value is greater than (numeric comparison)'], |
| 79 | + ['id' => 'less_than', 'name' => '<', 'desc' => 'Value is less than (numeric comparison)'], |
| 80 | + ['id' => 'greater_than_equal', 'name' => '>=', 'desc' => 'Value is greater than or equal to (numeric comparison)'], |
| 81 | + ['id' => 'less_than_equal', 'name' => '<=', 'desc' => 'Value is less than or equal to (numeric comparison)'], |
| 82 | + ]; |
| 83 | + } |
90 | 84 | } |
0 commit comments