-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathcheck-valid-method-names.php
139 lines (119 loc) · 4.9 KB
/
check-valid-method-names.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/*
+----------------------------------------------------------------------+
| PHP Version 8 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2021 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: George Peter Banyard <[email protected]> |
+----------------------------------------------------------------------+
| Description: This file parses the manual and outputs all erroneous |
| <methodname> tag usage. |
+----------------------------------------------------------------------+
*/
/* Path to the root of EN extension reference tree */
$doc_en_root = dirname(__DIR__, 3) . '/en/reference';
$total = 0;
function isMagicMethod(string $method): bool
{
switch ($method) {
case 'construct':
case 'destruct':
case 'tostring':
case 'call':
case 'callstatic':
case 'wakeup':
case 'sleep':
// case 'set': // TODO This conflicts with certain classes
// case 'get': // TODO This conflicts with certain classes
case 'isset':
case 'unset':
case 'setstate':
case 'clone':
return true;
default:
return false;
}
}
// TODO Need to add Predefined Interfaces/Classes
/* make a method list from files in extension directories */
function make_method_list(string $lang_doc_root): array
{
$methods = [];
foreach (new FilesystemIterator($lang_doc_root) as $extensions) {
if (!$extensions->isDir() || !$extensions->isReadable()) {
continue;
}
foreach (new FilesystemIterator($extensions->getPathname()) as $extension) {
if (!$extension->isDir() || !$extension->isReadable()) {
continue;
}
// Skip functions folder
if ($extension->getFilename() === 'functions') {
continue;
}
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($extension->getPathname(),
FilesystemIterator::SKIP_DOTS | FilesystemIterator::CURRENT_AS_FILEINFO));
foreach ($it as $file) {
if ($file->isDir() || !$file->isReadable()) {
continue;
}
$class = str_replace($extension->getPath() . '/', '', $file->getPath());
$class = str_replace('/', '\\', $class);
//$class = str_replace('-', '_', $class);
$class = strtolower($class);
$method = str_replace(['-', '.'], '_', $file->getBasename('.xml'));
$method = strtolower($method);
if (isMagicMethod($method)) { $method = '__' . $method; }
$fqn = $class . '::' . $method;
$methods[$fqn] = true;
}
}
}
return $methods;
}
echo "Building a list of methods...\n";
$methods = make_method_list($doc_en_root);
echo 'List complete. ' . count($methods) . " methods.\n";
echo "Checking the manual for <methodname> tags that contain invalid methods...\n";
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($doc_en_root)) as $file) {
if ($file->isDir() || !$file->isReadable()) {
continue;
}
$isFunction = false;
$name = $file->getBasename();
$path = $file->getPathname();
if (strpos($path, '/functions/') !== false) { $isFunction = true; }
$contents = file_get_contents($path);
if ($contents == '') {
continue;
}
if (preg_match_all('|<methodname>(.*?)</methodname>|s', $contents, $m)
&& is_array($m)
&& is_array($m[1]))
{
if ($isFunction) {
// Unset the first entry as it is the function prototype
unset($m[1][0]);
}
foreach ($m[1] as $fqn) {
$lcFqn = strtolower(trim($fqn));
if (!\array_key_exists($lcFqn, $methods)) {
//var_dump($fqn);
$total++;
$fileout = substr($file, strlen($doc_en_root) + 1);
printf("%-60.60s <methodname>$fqn</methodname>\n", $fileout);
}
}
}
}
echo "Found $total occurrences.\n";
exit((bool) $total);