Skip to content

Commit 5b4203e

Browse files
committed
fix json-check style
only whitespaces
1 parent 47b2480 commit 5b4203e

File tree

1 file changed

+71
-71
lines changed

1 file changed

+71
-71
lines changed

json-check.php

+71-71
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,85 @@
11
<?php
22

3-
declare(strict_types=1);
4-
5-
if ($argc == 1) {
6-
$mode = '';
7-
$dir = '.';
8-
} elseif ($argc == 2) {
9-
$mode = $argv[1];
10-
$dir = '.';
11-
} elseif ($argc == 3) {
12-
$mode = $argv[1];
13-
$dir = $argv[2];
14-
} else {
15-
die('JSON Checker cannot be run with this set of parameters!');
16-
}
17-
18-
if (!in_array($mode, ['', 'fix'])) {
19-
die('Unsupported mode "' . $mode . '"!');
20-
}
21-
22-
$start = microtime(true);
23-
$invalidFiles = jsonStyleCheck($dir, $mode);
24-
$duration = microtime(true) - $start;
25-
26-
foreach ($invalidFiles as $invalidFile) {
27-
echo $invalidFile . PHP_EOL;
28-
}
29-
30-
if (!empty($invalidFiles)) {
31-
echo PHP_EOL;
32-
}
33-
34-
echo 'Checked all files in ' . number_format($duration, 3) . ' seconds, ' . number_format(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB memory used' . PHP_EOL;
35-
36-
if (!empty($invalidFiles)) {
37-
exit(1);
38-
}
39-
40-
function jsonStyleCheck(string $dir, string $mode)
41-
{
42-
$ignore = ['./.vscode', './.idea', './.git', './libs/vendor'];
43-
$invalidFiles = [];
44-
$files = scandir($dir);
45-
foreach ($files as $file) {
46-
if ($file != '.' && $file != '..' && !in_array($dir, $ignore)) {
47-
if (is_dir($dir . '/' . $file)) {
48-
$invalidFiles = array_merge($invalidFiles, jsonStyleCheck($dir . '/' . $file, $mode));
49-
} else {
50-
if (fnmatch('*.json', $dir . '/' . $file)) {
51-
$invalidFile = checkContentInFile($dir . '/' . $file, $mode);
52-
if ($invalidFile !== false) {
53-
$invalidFiles[] = $invalidFile;
54-
}
3+
declare(strict_types=1);
4+
5+
if ($argc == 1) {
6+
$mode = '';
7+
$dir = '.';
8+
} elseif ($argc == 2) {
9+
$mode = $argv[1];
10+
$dir = '.';
11+
} elseif ($argc == 3) {
12+
$mode = $argv[1];
13+
$dir = $argv[2];
14+
} else {
15+
die('JSON Checker cannot be run with this set of parameters!');
16+
}
17+
18+
if (!in_array($mode, ['', 'fix'])) {
19+
die('Unsupported mode "' . $mode . '"!');
20+
}
21+
22+
$start = microtime(true);
23+
$invalidFiles = jsonStyleCheck($dir, $mode);
24+
$duration = microtime(true) - $start;
25+
26+
foreach ($invalidFiles as $invalidFile) {
27+
echo $invalidFile . PHP_EOL;
28+
}
29+
30+
if (!empty($invalidFiles)) {
31+
echo PHP_EOL;
32+
}
33+
34+
echo 'Checked all files in ' . number_format($duration, 3) . ' seconds, ' . number_format(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB memory used' . PHP_EOL;
35+
36+
if (!empty($invalidFiles)) {
37+
exit(1);
38+
}
39+
40+
function jsonStyleCheck(string $dir, string $mode)
41+
{
42+
$ignore = ['./.vscode', './.idea', './.git', './libs/vendor'];
43+
$invalidFiles = [];
44+
$files = scandir($dir);
45+
foreach ($files as $file) {
46+
if ($file != '.' && $file != '..' && !in_array($dir, $ignore)) {
47+
if (is_dir($dir . '/' . $file)) {
48+
$invalidFiles = array_merge($invalidFiles, jsonStyleCheck($dir . '/' . $file, $mode));
49+
} else {
50+
if (fnmatch('*.json', $dir . '/' . $file)) {
51+
$invalidFile = checkContentInFile($dir . '/' . $file, $mode);
52+
if ($invalidFile !== false) {
53+
$invalidFiles[] = $invalidFile;
5554
}
5655
}
5756
}
5857
}
59-
return $invalidFiles;
6058
}
59+
return $invalidFiles;
60+
}
6161

62-
function checkContentInFile(string $dir, string $mode)
63-
{
64-
$fileOriginal = file_get_contents($dir);
65-
66-
// Normalize line endings
67-
$fileOriginal = str_replace("\r\n", "\n", $fileOriginal);
68-
$fileOriginal = str_replace("\r", "\n", $fileOriginal);
62+
function checkContentInFile(string $dir, string $mode)
63+
{
64+
$fileOriginal = file_get_contents($dir);
6965

70-
// Ignore line break at the end of the file
71-
$fileOriginal = rtrim($fileOriginal, "\n");
66+
// Normalize line endings
67+
$fileOriginal = str_replace("\r\n", "\n", $fileOriginal);
68+
$fileOriginal = str_replace("\r", "\n", $fileOriginal);
7269

73-
// Reformat JSON using PHP
74-
$fileCompare = json_encode(json_decode($fileOriginal), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION);
70+
// Ignore line break at the end of the file
71+
$fileOriginal = rtrim($fileOriginal, "\n");
7572

76-
if ($fileOriginal == $fileCompare) {
77-
return false;
78-
}
73+
// Reformat JSON using PHP
74+
$fileCompare = json_encode(json_decode($fileOriginal), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION);
7975

80-
if ($mode == 'fix') {
81-
file_put_contents($dir, $fileCompare);
82-
}
76+
if ($fileOriginal == $fileCompare) {
77+
return false;
78+
}
8379

84-
return $dir;
80+
if ($mode == 'fix') {
81+
file_put_contents($dir, $fileCompare);
8582
}
83+
84+
return $dir;
85+
}

0 commit comments

Comments
 (0)