-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a lint test to check the code for any static calls to a non-static function which throws a fatal error as of PHP 8.0.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
require_once "class.test.php"; | ||
|
||
class StaticMethods extends Test { | ||
var $name = "Methods that should be static"; | ||
|
||
static function ignore3rdparty() { | ||
return false; | ||
} | ||
|
||
function testStaticMethods() { | ||
$scripts = static::getAllScripts(); | ||
$static_functions = array(); | ||
foreach ($scripts as $s) { | ||
$matches = array(); | ||
preg_match_all('/^\s*(?:\/\*[^*]*\*\/)?\s*' | ||
.'(?:(?:private|public|protected|static|abstract)\s+)+' | ||
.'function\s+&?\s*([^(\s]+)\s*\(/m', | ||
file_get_contents($s), $matches); | ||
$static_functions = array_merge($static_functions, $matches[1]); | ||
} | ||
foreach (static::find_function_calls($scripts) as $call) { | ||
list($file, $no, $line, $func) = $call; | ||
if ((strpos($line, 'parent::'.$func) === false) && | ||
(strpos($line, 'Unpacker::'.$func) === false) && | ||
(strpos($line, '::'.$func) !== false) && !in_array($func, $static_functions)) { | ||
$this->fail($file, $no, "$func: Function should be static"); | ||
} | ||
else { | ||
$this->pass(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return 'StaticMethods'; | ||
?> |