3
3
/**
4
4
* Script to auto-generate the `phars/index.html` page for the GH Pages website.
5
5
*
6
+ * {@internal This script has a minimum PHP requirement of PHP 7.0.}
7
+ *
6
8
* @copyright 2025 PHPCSStandards and contributors
7
9
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8
10
*/
9
11
10
12
// A directory containing files that are named {phpcs,phpcbf}-*.{phar,phar.asc}.
11
13
$ pharDir = __DIR__ . '/../src/phars ' ;
12
14
13
- $ allFiles = array_filter (scandir ($ pharDir ), function ($ file ) {
15
+ $ allFiles = array_filter (scandir ($ pharDir ), function (string $ file ) {
14
16
return preg_match ('/\.phar(\.asc)?$/ ' , $ file );
15
17
});
16
18
34
36
return version_compare ($ b , $ a );
35
37
});
36
38
37
- function indent (int $ level ): string
39
+ function indent (int $ level ): string
38
40
{
39
41
$ indentSpaces = ' ' ;
40
42
41
- $ output = "" ;
43
+ $ output = '' ;
42
44
43
45
for ($ i = 0 ; $ i < $ level ; $ i ++) {
44
46
$ output .= $ indentSpaces ;
@@ -47,36 +49,37 @@ function indent (int $level): string
47
49
return $ output ;
48
50
}
49
51
50
- function humanReadableFilesize ($ file ) {
52
+ function humanReadableFilesize (string $ file ): string
53
+ {
51
54
$ bytes = filesize ($ file );
52
55
53
- $ units = ['B ' , 'K ' , 'M ' , 'G ' ];
56
+ $ units = ['B ' , 'K ' , 'M ' , 'G ' ];
54
57
$ factor = floor ((strlen ($ bytes ) - 1 ) / 3 );
55
- return sprintf (" %.1f " , $ bytes / pow (1024 , $ factor )) . $ units [(int ) $ factor ];
58
+ return sprintf (' %.1f ' , $ bytes / pow (1024 , $ factor )) . $ units [(int ) $ factor ];
56
59
}
57
60
58
61
$ html = "<ul class= \"phar-list \"> \n" ;
59
62
60
63
foreach ($ filesGroupedByVersion as $ version => $ files ) {
61
64
sort ($ files );
62
65
63
- $ html .= indent (3 ) . "<li class= \"phar-list__version \"> \n" .
64
- indent (4 ) . " <h2 class= \ "phar-list__version-label \" > " . $ version . "</h2> \n" .
65
- indent (4 ) . "<ul class= \"phar-list__files \"> \n" ;
66
+ $ html .= indent (3 ) . "<li class= \"phar-list__version \"> \n"
67
+ . indent (4 ) . ' <h2 class="phar-list__version-label"> ' . $ version . "</h2> \n"
68
+ . indent (4 ) . "<ul class= \"phar-list__files \"> \n" ;
66
69
67
70
foreach ($ files as $ file ) {
68
71
$ fileSize = humanReadableFilesize ($ pharDir . '/ ' . $ file );
69
- $ lastModifiedDate = shell_exec (escapeshellcmd ("git log -1 --pretty= \"format:%cs \" -- " . $ pharDir . '/ ' . $ file ));
70
72
71
- $ html .= indent (5 ) . "<li><a download href= \"/phars/ " . htmlspecialchars ($ file ) . '"> ' . htmlspecialchars ($ file ) . "</a> <span class= \"phar-list__filesize \"> " . htmlspecialchars ($ fileSize ) . " | " . htmlspecialchars ($ lastModifiedDate ) . "</span></li> \n" ;
73
+ $ html .= indent (5 ) . '<li><a download href="/phars/ ' . htmlspecialchars ($ file ) . '"> ' . htmlspecialchars ($ file )
74
+ . '</a> <span class="phar-list__filesize"> ' . htmlspecialchars ($ fileSize ) . "</span></li> \n" ;
72
75
}
73
76
74
- $ html .= indent (4 ) . "</ul> \n" .
75
- indent (3 ) . "</li> \n" ;
77
+ $ html .= indent (4 ) . "</ul> \n"
78
+ . indent (3 ) . "</li> \n" ;
76
79
}
77
80
78
- $ html .= indent (2 ) . "</li> \n" .
79
- "</ul> \n" ;
81
+ $ html .= indent (2 ) . "</li> \n"
82
+ . "</ul> \n" ;
80
83
81
84
$ template = file_get_contents (__DIR__ . '/phars.html.template ' );
82
85
0 commit comments