Debian Codegraph @

extensions/Math/maintenance/SortTexutil.php

raw symbols SCIP
1 <?php
2
3 require_once __DIR__ . '/../../../maintenance/Maintenance.php';
4
5 class SortTexutil extends Maintenance {
6
7 public function execute() {
8 $jsonFilePath = './src/WikiTexVC/texutil.json';
9
10 $jsonContent = json_decode( file_get_contents( $jsonFilePath ), true );
11
12 if ( $jsonContent === null ) {
13 die( "Failed to decode texutil.json. Please check the file format.\n" );
14 }
15
16 foreach ( $jsonContent as $key => $value ) {
17 // Sort the entry alphabetically
18 ksort( $jsonContent["$key"] );
19 }
20 // Sort the entire file
21 ksort( $jsonContent );
22 $jsonString = json_encode( $jsonContent, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE );
23
24 $jsonStringWithTabs = preg_replace_callback( '/^( +)/m', static function ( $matches ) {
25 // Convert spaces to tabs (assuming 4 spaces per tab level)
26 return str_repeat( "\t", strlen( $matches[1] ) / 4 );
27 }, $jsonString ) . "\n";
28 // prevent eslint error Unnecessary escape character: \/ no-useless-escape
29 $jsonStringWithTabs = str_replace( '\/', '/', $jsonStringWithTabs );
30
31 file_put_contents( $jsonFilePath, $jsonStringWithTabs );
32
33 echo "texutil.json successfully sorted.\n";
34 }
35 }
36 $maintClass = SortTexutil::class;
37 require_once RUN_MAINTENANCE_IF_MAIN;