Subversion Repositories oidplus

Rev

Rev 1267 | Go to most recent revision | 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
 
34
$cntfiles = 0;
35
$cntcodes = 0;
36
$it = new RecursiveDirectoryIterator($dir);
37
$it->setFlags(FilesystemIterator::SKIP_DOTS); // DOES NOT WORK! Folders with . prefix still get evaluated!
38
foreach(new RecursiveIteratorIterator($it) as $file) {
39
        if ((strpos(str_replace('\\','/',realpath($file)),'/vendor/') !== false) && (strpos(str_replace('\\','/',realpath($file)),'/vendor/danielmarschall/') === false)) continue; // ignore third-party-code
40
        if (strpos(str_replace('\\','/',realpath($file)),'/dev/') !== false) continue; // ignore development utilities
41
 
42
        if (preg_match('@[/\\\\]\\.[^\\.]@',$file,$m)) continue; // Alternative to SKIP_DOTS
43
 
44
        if ($file->getExtension() == 'php') {
45
                $cont = file_get_contents($file);
46
                $cont = phpRemoveComments($cont);
47
 
48
                $cntfiles++;
49
 
50
                preg_match_all('@OIDplus::logger\(\)\->log\(\s*(["\'])([^"\']+)(["\'])@', $cont, $m);
51
                foreach ($m[2] as $str) {
52
                        $cntcodes++;
53
                        if (OIDplusLogger::parse_maskcode($str) === false) {
54
                                $file = substr($file, strlen($dir));
55
                                echo "Invalid maskcode '$str' in file '$file'\n";
56
                        } else {
1367 daniel-mar 57
                                if (VERBOSE) echo 'Valid: '.$str."\n";
1267 daniel-mar 58
                        }
59
                }
60
        }
61
}
62
echo "Done. Checked $cntcodes mask codes in $cntfiles files.\n";
63
 
64
# ---
65
 
66
/**
67
 * @param string $fileStr
68
 * @return string
69
 */
70
function phpRemoveComments(string $fileStr): string {
71
 
72
        // https://stackoverflow.com/questions/503871/best-way-to-automatically-remove-comments-from-php-code
73
 
74
        $newStr  = '';
75
 
76
        $commentTokens = array(T_COMMENT);
77
 
78
        if (defined('T_DOC_COMMENT')) $commentTokens[] = T_DOC_COMMENT; // PHP 5
79
        if (defined('T_ML_COMMENT'))  $commentTokens[] = T_ML_COMMENT;  // PHP 4
80
 
81
        $tokens = token_get_all($fileStr);
82
 
83
        foreach ($tokens as $token) {
84
                if (is_array($token)) {
85
                        if (in_array($token[0], $commentTokens)) continue;
86
                        $token = $token[1];
87
                }
88
                $newStr .= $token;
89
        }
90
 
91
        return $newStr;
92
 
93
}