PluginProbe
WPIDE – File Manager & Code Editor / 3.5.9
WPIDE – File Manager & Code Editor v3.5.9
3.5.9 3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 All 55 releases
wpide / App / Helpers / PhpValidator.php

PhpValidator.php in WPIDE – File Manager & Code Editor 3.5.9, at App/Helpers/PhpValidator.php

52 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPIDE\App\Helpers;
3
4 use Exception;
5 use PhpParser\ParserFactory;
6
7 class PhpValidator
8 {
9
10 /**
11 * @throws Exception
12 */
13 public static function validate($content)
14 {
15 self::parse($content);
16 //self::validateConstants($content);
17 }
18
19 public static function parse($content) {
20
21 $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
22 $parser->parse($content);
23 }
24
25 /**
26 * @throws Exception
27 */
28 protected static function validateConstants($content)
29 {
30
31 $pattern = '/define\((.+?),.+?\)/';
32 if (preg_match_all($pattern, $content, $matches)) {
33
34 $matches = array_map(function ($match) {
35 return trim(str_replace(['"', "'"], "", $match));
36 }, $matches[1]);
37
38 $duplicates = array();
39 foreach (array_count_values($matches) as $val => $c) {
40 if ($c > 1) {
41 $duplicates[] = $val;
42 }
43 }
44
45 if (!empty($duplicates)) {
46 $constant = array_shift($duplicates);
47 throw new Exception('Constant ' . $constant . ' already defined!');
48 }
49 }
50 }
51 }
52