Rev 1367 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1267 | daniel-mar | 1 | #!/usr/bin/env php |
2 | <?php |
||
3 | |||
4 | /* |
||
5 | * OIDplus 2.0 |
||
6 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
||
7 | * |
||
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
9 | * you may not use this file except in compliance with the License. |
||
10 | * You may obtain a copy of the License at |
||
11 | * |
||
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
13 | * |
||
14 | * Unless required by applicable law or agreed to in writing, software |
||
15 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
17 | * See the License for the specific language governing permissions and |
||
18 | * limitations under the License. |
||
19 | */ |
||
20 | |||
21 | $dir = __DIR__ . '/../../'; |
||
22 | |||
23 | define('INSIDE_OIDPLUS',true); |
||
1367 | daniel-mar | 24 | include_once $dir.'vendor/danielmarschall/php_utils/misc_functions.inc.php'; // PHP 7.x compat functions |
1267 | daniel-mar | 25 | require_once $dir.'includes/classes/OIDplusBaseClass.class.php'; |
26 | require_once $dir.'includes/classes/OIDplusLogger.class.php'; |
||
27 | |||
1367 | daniel-mar | 28 | const VERBOSE = false; |
29 | |||
1267 | daniel-mar | 30 | use ViaThinkSoft\OIDplus\OIDplusLogger; |
31 | |||
32 | // --- |
||
33 | |||
1436 | daniel-mar | 34 | $errors_found = false; |
35 | |||
1267 | daniel-mar | 36 | $cntfiles = 0; |
37 | $cntcodes = 0; |
||
38 | $it = new RecursiveDirectoryIterator($dir); |
||
39 | $it->setFlags(FilesystemIterator::SKIP_DOTS); // DOES NOT WORK! Folders with . prefix still get evaluated! |
||
40 | foreach(new RecursiveIteratorIterator($it) as $file) { |
||
41 | if ((strpos(str_replace('\\','/',realpath($file)),'/vendor/') !== false) && (strpos(str_replace('\\','/',realpath($file)),'/vendor/danielmarschall/') === false)) continue; // ignore third-party-code |
||
42 | if (strpos(str_replace('\\','/',realpath($file)),'/dev/') !== false) continue; // ignore development utilities |
||
43 | |||
44 | if (preg_match('@[/\\\\]\\.[^\\.]@',$file,$m)) continue; // Alternative to SKIP_DOTS |
||
45 | |||
46 | if ($file->getExtension() == 'php') { |
||
47 | $cont = file_get_contents($file); |
||
48 | $cont = phpRemoveComments($cont); |
||
49 | |||
50 | $cntfiles++; |
||
51 | |||
52 | preg_match_all('@OIDplus::logger\(\)\->log\(\s*(["\'])([^"\']+)(["\'])@', $cont, $m); |
||
53 | foreach ($m[2] as $str) { |
||
54 | $cntcodes++; |
||
55 | if (OIDplusLogger::parse_maskcode($str) === false) { |
||
56 | $file = substr($file, strlen($dir)); |
||
57 | echo "Invalid maskcode '$str' in file '$file'\n"; |
||
1436 | daniel-mar | 58 | $errors_found = true; |
1267 | daniel-mar | 59 | } else { |
1367 | daniel-mar | 60 | if (VERBOSE) echo 'Valid: '.$str."\n"; |
1267 | daniel-mar | 61 | } |
62 | } |
||
63 | } |
||
64 | } |
||
65 | echo "Done. Checked $cntcodes mask codes in $cntfiles files.\n"; |
||
66 | |||
1436 | daniel-mar | 67 | exit($errors_found ? 1 : 0); |
68 | |||
1267 | daniel-mar | 69 | # --- |
70 | |||
71 | /** |
||
72 | * @param string $fileStr |
||
73 | * @return string |
||
74 | */ |
||
75 | function phpRemoveComments(string $fileStr): string { |
||
76 | |||
77 | // https://stackoverflow.com/questions/503871/best-way-to-automatically-remove-comments-from-php-code |
||
78 | |||
79 | $newStr = ''; |
||
80 | |||
81 | $commentTokens = array(T_COMMENT); |
||
82 | |||
83 | if (defined('T_DOC_COMMENT')) $commentTokens[] = T_DOC_COMMENT; // PHP 5 |
||
84 | if (defined('T_ML_COMMENT')) $commentTokens[] = T_ML_COMMENT; // PHP 4 |
||
85 | |||
86 | $tokens = token_get_all($fileStr); |
||
87 | |||
88 | foreach ($tokens as $token) { |
||
89 | if (is_array($token)) { |
||
90 | if (in_array($token[0], $commentTokens)) continue; |
||
91 | $token = $token[1]; |
||
92 | } |
||
93 | $newStr .= $token; |
||
94 | } |
||
95 | |||
96 | return $newStr; |
||
97 | |||
98 | } |