Subversion Repositories oidplus

Rev

Rev 1367 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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