Skip to content

Commit 9052667

Browse files
Merge pull request #35 from Sesquipedalian/release-3.0
Updates check-eof.php to check for no closing PHP tag and one newline
2 parents 8ca76ba + 9e5b1ab commit 9052667

File tree

1 file changed

+23
-39
lines changed

1 file changed

+23
-39
lines changed

check-eof.php

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,31 @@
1313

1414
// Stuff we will ignore.
1515
$ignoreFiles = [
16-
'\./cache/',
17-
'\./other/',
18-
'\./tests/',
19-
'\./vendor/',
20-
21-
// Minify Stuff.
22-
'\./Sources/minify/',
23-
24-
// random_compat().
25-
'\./Sources/random_compat/',
26-
27-
// ReCaptcha Stuff.
28-
'\./Sources/ReCaptcha/',
16+
'./cache/',
17+
'./other/',
18+
'./tests/',
19+
'./vendor/',
20+
'./.git',
21+
'./Sources/minify/',
22+
'./Sources/ReCaptcha/',
23+
'./ZxcvbnPhp/',
2924

3025
// We will ignore Settings.php if this is a live dev site.
31-
'\./Settings\.php',
32-
'\./Settings_bak\.php',
33-
'\./db_last_error\.php',
26+
'./Settings.php',
27+
'./Settings_bak.php',
28+
'./db_last_error.php',
3429
];
3530

3631
try {
37-
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.', FilesystemIterator::UNIX_PATHS)) as $currentFile => $fileInfo) {
32+
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(realpath('.'), FilesystemIterator::UNIX_PATHS)) as $currentFile => $fileInfo) {
3833
// Starts with a dot, skip. Also gets Mac OS X resource files.
39-
if ($currentFile[0] == '.') {
34+
if (str_starts_with($fileInfo->getBasename(), '.')) {
4035
continue;
4136
}
4237

4338
if ($fileInfo->getExtension() == 'php') {
4439
foreach ($ignoreFiles as $if) {
45-
if (preg_match('~' . $if . '~i', $currentFile)) {
40+
if (file_exists($if) && preg_match('~' . preg_quote(realpath($if), '~') . '~i', $currentFile)) {
4641
continue 2;
4742
}
4843
}
@@ -52,32 +47,21 @@
5247
fseek($file, -100, SEEK_END);
5348
$contents = fread($file, 100);
5449

55-
// There is some white space here.
56-
if (preg_match('~\?>\s+$~', $contents, $matches)) {
57-
throw new Exception('End of File contains extra spaces in ' . $currentFile);
58-
}
59-
60-
// Test to see if its there even, SMF 2.1 base package needs it there in our main files to allow package manager to properly handle end operations. Customizations do not need it.
61-
if (!preg_match('~\?>$~', $contents, $matches)) {
62-
throw new Exception('End of File missing in ' . $currentFile);
63-
}
64-
65-
// Test to see if a function/class ending is here but with no return (because we are OCD).
66-
if (preg_match('~}([\r]?\n)?\?>~', $contents, $matches)) {
67-
throw new Exception('Incorrect return(s) after last function/class but before EOF in ' . $currentFile);
50+
// We don't want closing PHP tags in SMF 3.0+.
51+
if (preg_match('~\s*\?>\s*$~', $contents, $matches)) {
52+
throw new Exception('Closing PHP tag found in ' . $currentFile . '. Please remove it.');
6853
}
6954

70-
// Test to see if a string ending is here but with no return (because we are OCD).
71-
if (preg_match('~;([\r]?\n)?\?>~', $contents, $matches)) {
72-
throw new Exception('Incorrect return(s) after last string but before EOF in ' . $currentFile);
55+
// Make sure we end with exactly one newline.
56+
if (strlen($contents) > 0 && !preg_match('~\S\n$~', $contents, $matches)) {
57+
throw new Exception('Incorrect number of newlines at EOF in ' . $currentFile);
7358
}
7459
} else {
7560
throw new Exception('Unable to open file ' . $currentFile);
7661
}
7762
}
7863
}
79-
}
80-
catch (Exception $e) {
81-
fwrite(STDERR, $e->getMessage());
64+
} catch (Exception $e) {
65+
fwrite(STDERR, $e->getMessage() . "\n");
8266
exit(1);
83-
}
67+
}

0 commit comments

Comments
 (0)