@@ -56,13 +56,13 @@ function formatDate(string $dateString, string|null $format, string $locale): st
56
56
/**
57
57
* Check theme and color customization parameters to generate a theme mapping
58
58
*
59
- * @param array<string, string> $params Request parameters
60
- * @return array<string, string> The chosen theme or default
59
+ * @param array<string,string> $params Request parameters
60
+ * @return array<string,string> The chosen theme or default
61
61
*/
62
62
function getRequestedTheme (array $ params ): array
63
63
{
64
64
/**
65
- * @var array<string, array<string, string>> $THEMES
65
+ * @var array<string,array<string,string>> $THEMES
66
66
* List of theme names mapped to labeled colors
67
67
*/
68
68
$ THEMES = include "themes.php " ;
@@ -125,7 +125,7 @@ function getRequestedTheme(array $params): array
125
125
* than the word width.
126
126
* @return string The given string wrapped at the specified length
127
127
*/
128
- function utf8WordWrap ($ string , $ width = 75 , $ break = "\n" , $ cut_long_words = false )
128
+ function utf8WordWrap (string $ string , int $ width = 75 , string $ break = "\n" , bool $ cut_long_words = false ): string
129
129
{
130
130
// match anything 1 to $width chars long followed by whitespace or EOS
131
131
$ string = preg_replace ("/(.{1, $ width})(?:\s|$)/uS " , "$1 $ break " , $ string );
@@ -145,7 +145,7 @@ function utf8WordWrap($string, $width = 75, $break = "\n", $cut_long_words = fal
145
145
* @param string $string The input string
146
146
* @return int The length of the string
147
147
*/
148
- function utf8Strlen ($ string )
148
+ function utf8Strlen (string $ string ): int
149
149
{
150
150
return preg_match_all ("/./us " , $ string , $ matches );
151
151
}
@@ -156,7 +156,6 @@ function utf8Strlen($string)
156
156
* @param string $text Text to split
157
157
* @param int $maxChars Maximum number of characters per line
158
158
* @param int $line1Offset Offset for the first line
159
- *
160
159
* @return string Original text if one line, or split text with <tspan> elements
161
160
*/
162
161
function splitLines (string $ text , int $ maxChars , int $ line1Offset ): string
@@ -184,7 +183,6 @@ function splitLines(string $text, int $maxChars, int $line1Offset): string
184
183
* Normalize a locale code
185
184
*
186
185
* @param string $localeCode Locale code
187
- *
188
186
* @return string Normalized locale code
189
187
*/
190
188
function normalizeLocaleCode (string $ localeCode ): string
@@ -210,10 +208,9 @@ function normalizeLocaleCode(string $localeCode): string
210
208
* Get the translations for a locale code after normalizing it
211
209
*
212
210
* @param string $localeCode Locale code
213
- *
214
211
* @return array Translations for the locale code
215
212
*/
216
- function getTranslations (string $ localeCode )
213
+ function getTranslations (string $ localeCode ): array
217
214
{
218
215
// normalize locale code
219
216
$ localeCode = normalizeLocaleCode ($ localeCode );
@@ -239,9 +236,8 @@ function getTranslations(string $localeCode)
239
236
/**
240
237
* Generate SVG output for a stats array
241
238
*
242
- * @param array<string, mixed> $stats Streak stats
243
- * @param array<string, string>|NULL $params Request parameters
244
- *
239
+ * @param array<string,mixed> $stats Streak stats
240
+ * @param array<string,string>|NULL $params Request parameters
245
241
* @return string The generated SVG Streak Stats card
246
242
*
247
243
* @throws InvalidArgumentException If a locale does not exist
@@ -424,8 +420,7 @@ function generateCard(array $stats, array $params = null): string
424
420
* Generate SVG displaying an error message
425
421
*
426
422
* @param string $message The error message to display
427
- * @param array<string, string>|NULL $params Request parameters
428
- *
423
+ * @param array<string,string>|NULL $params Request parameters
429
424
* @return string The generated SVG error card
430
425
*/
431
426
function generateErrorCard (string $ message , array $ params = null ): string
@@ -485,7 +480,6 @@ function generateErrorCard(string $message, array $params = null): string
485
480
* Converts an SVG card to a PNG image
486
481
*
487
482
* @param string $svg The SVG for the card as a string
488
- *
489
483
* @return string The generated PNG data
490
484
*/
491
485
function convertSvgToPng (string $ svg ): string
@@ -516,7 +510,7 @@ function convertSvgToPng(string $svg): string
516
510
if (empty ($ png )) {
517
511
// `2>&1`: redirect stderr to stdout
518
512
$ error = shell_exec ("$ cmd 2>&1 " ); // skipcq: PHP-A1009
519
- throw new Exception ("Failed to convert SVG to PNG: {$ error }" , 500 );
513
+ throw new InvalidArgumentException ("Failed to convert SVG to PNG: {$ error }" , 500 );
520
514
}
521
515
522
516
// return the generated png
@@ -527,7 +521,6 @@ function convertSvgToPng(string $svg): string
527
521
* Return headers and response based on type
528
522
*
529
523
* @param string|array $output The stats (array) or error message (string) to display
530
- *
531
524
* @return array The Content-Type header and the response body, and status code in case of an error
532
525
*/
533
526
function generateOutput (string |array $ output ): array
@@ -573,6 +566,7 @@ function generateOutput(string|array $output): array
573
566
*
574
567
* @param string|array $output The Content-Type header and the response body
575
568
* @param int $responseCode The HTTP response code to send
569
+ * @return void The function exits after sending the response
576
570
*/
577
571
function renderOutput (string |array $ output , int $ responseCode = 200 ): void
578
572
{
0 commit comments