2121class Debugger
2222{
2323 /**
24+ * Contains the Collections.
25+ * Keys are the names and values are the Collections.
26+ *
2427 * @var array<string,Collection>
2528 */
2629 protected array $ collections = [];
2730 /**
31+ * Contains the debug options.
32+ * The keys are the names of the options.
33+ *
2834 * @var array<string,mixed>
2935 */
3036 protected array $ options = [];
37+ /**
38+ * Contains the path to the debugbar view file.
39+ *
40+ * @var string
41+ */
3142 protected string $ debugbarView = __DIR__ . '/Views/debugbar/debugbar.php ' ;
43+ /**
44+ * Tells if the debugbar is enabled.
45+ *
46+ * @var bool
47+ */
3248 protected bool $ debugbarEnabled = true ;
3349
50+ /**
51+ * Add a new Collection.
52+ *
53+ * @param Collection $collection
54+ *
55+ * @return static
56+ */
3457 public function addCollection (Collection $ collection ) : static
3558 {
3659 $ this ->collections [$ collection ->getName ()] = $ collection ;
3760 return $ this ;
3861 }
3962
4063 /**
41- * @return array<string,Collection>
64+ * Get all Collections.
65+ *
66+ * @return array<string,Collection> An array where the keys are the names of
67+ * the collections and the values are the collections
4268 */
4369 public function getCollections () : array
4470 {
4571 return $ this ->collections ;
4672 }
4773
74+ /**
75+ * Get a Collection by name.
76+ *
77+ * @param string $name The name of the Collection
78+ *
79+ * @return Collection|null The collection or null if it does not exist
80+ */
4881 public function getCollection (string $ name ) : ?Collection
4982 {
5083 return $ this ->getCollections ()[$ name ] ?? null ;
5184 }
5285
86+ /**
87+ * Add a collector to a collection.
88+ *
89+ * If a collection with the given name does not exist, a new one will be
90+ * created.
91+ *
92+ * @param Collector $collector The collector
93+ * @param string $collectionName The name of the collection
94+ *
95+ * @return static
96+ */
5397 public function addCollector (Collector $ collector , string $ collectionName ) : static
5498 {
5599 $ collection = $ this ->getCollection ($ collectionName );
@@ -62,10 +106,12 @@ public function addCollector(Collector $collector, string $collectionName) : sta
62106 }
63107
64108 /**
109+ * Set a debug option.
110+ *
65111 * @since 4.5
66112 *
67- * @param string $name
68- * @param mixed $value
113+ * @param string $name The name of the option
114+ * @param mixed $value The value of the option
69115 *
70116 * @return static
71117 */
@@ -76,19 +122,23 @@ public function setOption(string $name, mixed $value) : static
76122 }
77123
78124 /**
125+ * Get the value of a debug option.
126+ *
79127 * @since 4.5
80128 *
81- * @param string $name
129+ * @param string $name The name of the option
82130 *
83- * @return mixed
131+ * @return mixed The value of the option or null
84132 */
85133 public function getOption (string $ name ) : mixed
86134 {
87135 return $ this ->options [$ name ] ?? null ;
88136 }
89137
90138 /**
91- * @param array<string,mixed> $options
139+ * Set all debug options.
140+ *
141+ * @param array<string,mixed> $options All options
92142 *
93143 * @return static
94144 */
@@ -99,6 +149,8 @@ public function setOptions(array $options) : static
99149 }
100150
101151 /**
152+ * Get all debug options.
153+ *
102154 * @return array<string,mixed>
103155 */
104156 public function getOptions () : array
@@ -107,6 +159,9 @@ public function getOptions() : array
107159 }
108160
109161 /**
162+ * Get an array with the minimum, maximum, and total execution times for
163+ * all activities. Also, returns an array with all collected activities.
164+ *
110165 * @return array<string,mixed>
111166 */
112167 #[ArrayShape([
@@ -144,9 +199,16 @@ public function getActivities() : array
144199 }
145200
146201 /**
147- * @param array<string,mixed> $activity
148- * @param float $min
149- * @param float $max
202+ * Updates the $activity variable.
203+ *
204+ * Adds the "total" key representing the total execution time.
205+ *
206+ * Adds the "left" and "width" keys representing the CSS `margin-left` and
207+ * `width` properties used to create the time bar.
208+ *
209+ * @param array<string,mixed> $activity Current activity
210+ * @param float $min The minimum time of the collected activities
211+ * @param float $max The maximum time of collected activities
150212 */
151213 protected function addActivityValues (array &$ activity , float $ min , float $ max ) : void
152214 {
@@ -161,6 +223,13 @@ protected function addActivityValues(array &$activity, float $min, float $max) :
161223 $ activity ['width ' ] = .0 ;
162224 }
163225
226+ /**
227+ * Set the path of the debugbar view.
228+ *
229+ * @param string $file The view file path
230+ *
231+ * @return static
232+ */
164233 public function setDebugbarView (string $ file ) : static
165234 {
166235 $ realpath = \realpath ($ file );
@@ -173,11 +242,21 @@ public function setDebugbarView(string $file) : static
173242 return $ this ;
174243 }
175244
245+ /**
246+ * Get the path of the debugbar view.
247+ *
248+ * @return string
249+ */
176250 public function getDebugbarView () : string
177251 {
178252 return $ this ->debugbarView ;
179253 }
180254
255+ /**
256+ * Render the debug bar, if it is enabled.
257+ *
258+ * @return string The debug bar (if enabled) or a blank string
259+ */
181260 public function renderDebugbar () : string
182261 {
183262 if (!$ this ->isDebugbarEnabled ()) {
@@ -230,6 +309,13 @@ public function disableDebugbar() : static
230309 return $ this ;
231310 }
232311
312+ /**
313+ * Replace a list of characters with hyphens.
314+ *
315+ * @param string $name The name to be updated
316+ *
317+ * @return string Returns the name with replacements
318+ */
233319 public static function makeSafeName (string $ name ) : string
234320 {
235321 return \strtr (\trim (\strip_tags (\strtolower ($ name ))), [
@@ -245,6 +331,13 @@ public static function makeSafeName(string $name) : string
245331 ]);
246332 }
247333
334+ /**
335+ * Convert size to unit of measurement.
336+ *
337+ * @param float|int $size The size in bytes
338+ *
339+ * @return string Returns the size with unit of measurement
340+ */
248341 public static function convertSize (float | int $ size ) : string
249342 {
250343 if (empty ($ size )) {
@@ -255,6 +348,13 @@ public static function convertSize(float | int $size) : string
255348 return \round ($ size / (1024 ** $ index ), 3 ) . ' ' . $ unit [$ index ];
256349 }
257350
351+ /**
352+ * Make a value into a debug value.
353+ *
354+ * @param mixed $value Any value
355+ *
356+ * @return string The value made
357+ */
258358 public static function makeDebugValue (mixed $ value ) : string
259359 {
260360 $ type = \get_debug_type ($ value );
@@ -271,9 +371,9 @@ public static function makeDebugValue(mixed $value) : string
271371 /**
272372 * Remove dots and zeros from the end of the version.
273373 *
274- * @param string $version
374+ * @param string $version The version
275375 *
276- * @return string
376+ * @return string The updated version
277377 */
278378 public static function roundVersion (string $ version ) : string
279379 {
@@ -284,6 +384,14 @@ public static function roundVersion(string $version) : string
284384 return $ version ;
285385 }
286386
387+ /**
388+ * Round seconds to milliseconds.
389+ *
390+ * @param float|int $seconds The number of seconds
391+ * @param int $precision The number of decimal digits to round
392+ *
393+ * @return float Returns the value in milliseconds
394+ */
287395 public static function roundSecondsToMilliseconds (float | int $ seconds , int $ precision = 3 ) : float
288396 {
289397 return \round ($ seconds * 1000 , $ precision );
0 commit comments