@@ -107,32 +107,32 @@ public static function fromSnapshots(Snapshot $start, Snapshot $end): self
107107 public static function fromArray (array $ data ): self
108108 {
109109 $ missingKeys = array_diff_key ([
110- ' cpu_time ' => 1 ,
111- ' execution_time ' => 1 ,
112- ' memory_usage ' => 1 ,
113- ' memory_usage_growth ' => 1 ,
114- ' real_memory_usage ' => 1 ,
115- ' real_memory_usage_growth ' => 1 ,
116- ' peak_memory_usage ' => 1 ,
117- ' peak_memory_usage_growth ' => 1 ,
118- ' real_peak_memory_usage ' => 1 ,
119- ' real_peak_memory_usage_growth ' => 1 ,
110+ MetricType::CpuTime-> value => 1 ,
111+ MetricType::ExecutionTime-> value => 1 ,
112+ MetricType::MemoryUsage-> value => 1 ,
113+ MetricType::MemoryUsageGrowth-> value => 1 ,
114+ MetricType::RealMemoryUsage-> value => 1 ,
115+ MetricType::RealMemoryUsageGrowth-> value => 1 ,
116+ MetricType::PeakMemoryUsage-> value => 1 ,
117+ MetricType::PeakMemoryUsageGrowth-> value => 1 ,
118+ MetricType::RealPeakMemoryUsage-> value => 1 ,
119+ MetricType::RealPeakMemoryUsageGrowth-> value => 1 ,
120120 ], $ data );
121121
122122 [] === $ missingKeys || throw new InvalidArgument ('The payload is missing the following keys: ' .implode (', ' , array_keys ($ missingKeys )));
123123
124124 try {
125125 return new self (
126- $ data [' cpu_time ' ],
127- $ data [' execution_time ' ],
128- $ data [' memory_usage ' ],
129- $ data [' memory_usage_growth ' ],
130- $ data [' real_memory_usage ' ],
131- $ data [' real_memory_usage_growth ' ],
132- $ data [' peak_memory_usage ' ],
133- $ data [' peak_memory_usage_growth ' ],
134- $ data [' real_peak_memory_usage ' ],
135- $ data [' real_peak_memory_usage_growth ' ],
126+ cpuTime: $ data [MetricType::CpuTime-> value ],
127+ executionTime: $ data [MetricType::ExecutionTime-> value ],
128+ memoryUsage: $ data [MetricType::MemoryUsage-> value ],
129+ memoryUsageGrowth: $ data [MetricType::MemoryUsageGrowth-> value ],
130+ peakMemoryUsage: $ data [MetricType::PeakMemoryUsage-> value ],
131+ peakMemoryUsageGrowth: $ data [MetricType::PeakMemoryUsageGrowth-> value ],
132+ realMemoryUsage: $ data [MetricType::RealMemoryUsage-> value ],
133+ realMemoryUsageGrowth: $ data [MetricType::RealMemoryUsageGrowth-> value ],
134+ realPeakMemoryUsage: $ data [MetricType::RealPeakMemoryUsage-> value ],
135+ realPeakMemoryUsageGrowth: $ data [MetricType::RealPeakMemoryUsageGrowth-> value ],
136136 );
137137 } catch (Throwable $ exception ) {
138138 throw new InvalidArgument ('Unable to create a metrics from the payload ' , previous: $ exception );
@@ -153,16 +153,16 @@ public function jsonSerialize(): array
153153 public function toArray (): array
154154 {
155155 return [
156- ' cpu_time ' => $ this ->cpuTime ,
157- ' execution_time ' => $ this ->executionTime ,
158- ' memory_usage ' => $ this ->memoryUsage ,
159- ' memory_usage_growth ' => $ this ->memoryUsageGrowth ,
160- ' real_memory_usage ' => $ this ->realMemoryUsage ,
161- ' real_memory_usage_growth ' => $ this ->realMemoryUsageGrowth ,
162- ' peak_memory_usage ' => $ this ->peakMemoryUsage ,
163- ' peak_memory_usage_growth ' => $ this ->peakMemoryUsageGrowth ,
164- ' real_peak_memory_usage ' => $ this ->realPeakMemoryUsage ,
165- ' real_peak_memory_usage_growth ' => $ this ->realPeakMemoryUsageGrowth ,
156+ MetricType::CpuTime-> value => $ this ->cpuTime ,
157+ MetricType::ExecutionTime-> value => $ this ->executionTime ,
158+ MetricType::MemoryUsage-> value => $ this ->memoryUsage ,
159+ MetricType::MemoryUsageGrowth-> value => $ this ->memoryUsageGrowth ,
160+ MetricType::RealMemoryUsage-> value => $ this ->realMemoryUsage ,
161+ MetricType::RealMemoryUsageGrowth-> value => $ this ->realMemoryUsageGrowth ,
162+ MetricType::PeakMemoryUsage-> value => $ this ->peakMemoryUsage ,
163+ MetricType::PeakMemoryUsageGrowth-> value => $ this ->peakMemoryUsageGrowth ,
164+ MetricType::RealPeakMemoryUsage-> value => $ this ->realPeakMemoryUsage ,
165+ MetricType::RealPeakMemoryUsageGrowth-> value => $ this ->realPeakMemoryUsageGrowth ,
166166 ];
167167 }
168168
@@ -172,16 +172,16 @@ public function toArray(): array
172172 public function toHuman (): array
173173 {
174174 return [
175- ' cpu_time ' => DurationUnit::format ($ this ->cpuTime , 3 ),
176- ' execution_time ' => DurationUnit::format ($ this ->executionTime , 3 ),
177- ' memory_usage ' => MemoryUnit::format ($ this ->memoryUsage , 1 ),
178- ' memory_usage_growth ' => MemoryUnit::format ($ this ->memoryUsageGrowth , 1 ),
179- ' real_memory_usage ' => MemoryUnit::format ($ this ->realMemoryUsage , 1 ),
180- ' real_memory_usage_growth ' => MemoryUnit::format ($ this ->realMemoryUsageGrowth , 1 ),
181- ' peak_memory_usage ' => MemoryUnit::format ($ this ->peakMemoryUsage , 1 ),
182- ' peak_memory_usage_growth ' => MemoryUnit::format ($ this ->peakMemoryUsageGrowth , 1 ),
183- ' real_peak_memory_usage ' => MemoryUnit::format ($ this ->realPeakMemoryUsage , 1 ),
184- ' real_peak_memory_usage_growth ' => MemoryUnit::format ($ this ->realPeakMemoryUsageGrowth , 1 ),
175+ MetricType::CpuTime-> value => DurationUnit::format ($ this ->cpuTime , 3 ),
176+ MetricType::ExecutionTime-> value => DurationUnit::format ($ this ->executionTime , 3 ),
177+ MetricType::MemoryUsage-> value => MemoryUnit::format ($ this ->memoryUsage , 1 ),
178+ MetricType::MemoryUsageGrowth-> value => MemoryUnit::format ($ this ->memoryUsageGrowth , 1 ),
179+ MetricType::RealMemoryUsage-> value => MemoryUnit::format ($ this ->realMemoryUsage , 1 ),
180+ MetricType::RealMemoryUsageGrowth-> value => MemoryUnit::format ($ this ->realMemoryUsageGrowth , 1 ),
181+ MetricType::PeakMemoryUsage-> value => MemoryUnit::format ($ this ->peakMemoryUsage , 1 ),
182+ MetricType::PeakMemoryUsageGrowth-> value => MemoryUnit::format ($ this ->peakMemoryUsageGrowth , 1 ),
183+ MetricType::RealPeakMemoryUsage-> value => MemoryUnit::format ($ this ->realPeakMemoryUsage , 1 ),
184+ MetricType::RealPeakMemoryUsageGrowth-> value => MemoryUnit::format ($ this ->realPeakMemoryUsageGrowth , 1 ),
185185 ];
186186 }
187187
0 commit comments