|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
function getEntityRepository($content){ |
|
4
|
|
|
return getArgumentOfKeyword($content, 'use'); |
|
5
|
|
|
} |
|
6
|
|
|
|
|
7
|
|
|
function getNamespace($content) |
|
8
|
|
|
{ |
|
9
|
|
|
return getArgumentOfKeyword($content, 'namespace'); |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
function getEntityXYRepository($content){ |
|
13
|
|
|
$fcerX = getEntityRepository($content, 'use'); |
|
|
|
|
|
|
14
|
|
|
$pos = strpos($content, $fcerX); |
|
15
|
|
|
$fcerY = getEntityRepository(substr($content, $pos+strlen($fcerX)), 'use'); |
|
16
|
|
|
return [$fcerX, $fcerY]; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
function getArgumentOfKeyword($content, $keyword){ |
|
20
|
|
|
if( ($pos = strpos($content, $keyword.' ')) === false ) { |
|
21
|
|
|
echo $keyword.' not found'."\n"; |
|
22
|
|
|
exit(2); |
|
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
$vendor = $pos+strlen($keyword)+1; |
|
25
|
|
|
|
|
26
|
|
|
if( ($pos = strpos($content, '\\', $pos)) === false ) { |
|
27
|
|
|
echo $keyword.' has no backslash'."\n"; |
|
28
|
|
|
exit(3); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
if( ($end = strpos($content, ';', $pos)) === false ) { |
|
32
|
|
|
echo $keyword.' does not end in ;'."\n"; |
|
33
|
|
|
exit(4); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
return substr($content, $vendor, $end-$vendor); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
// TODO rename namespace2pathVendorStripped |
|
40
|
|
|
function namespace2dir($namespace){ |
|
41
|
|
|
$pos = strpos($namespace, '\\'); |
|
42
|
|
|
$vs = substr($namespace, $pos); |
|
43
|
|
|
return str_replace('\\', '/', $vs); // DIRECTORY_SEPARATOR |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// https://www.php.net/manual/en/function.file-put-contents.php#84180 |
|
47
|
|
|
function file_force_contents($destination, $contents) |
|
48
|
|
|
{ |
|
49
|
|
|
$parts = explode('/', $destination); |
|
50
|
|
|
$file = array_pop($parts); |
|
|
|
|
|
|
51
|
|
|
$dir = ''; |
|
52
|
|
|
foreach ($parts as $part) { |
|
53
|
|
|
if (!is_dir($dir .= "$part/")) mkdir($dir); |
|
54
|
|
|
} |
|
55
|
|
|
if( is_file($destination) ){ |
|
56
|
|
|
rename($destination, $destination . '.bak'); |
|
57
|
|
|
} |
|
58
|
|
|
return file_put_contents($destination, $contents); |
|
59
|
|
|
} |
|
60
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.