detect (multiple) classes definde in a file

This commit is contained in:
Ralf Becker 2016-03-21 21:22:09 +00:00
parent 77c5102792
commit 1622ebc442

View File

@ -34,6 +34,16 @@ function check_namespace($file)
return str_repeat("\n", substr_count($matches[0], "\n"));
}, $content);
// find classes declared in file itself, in case they are used
$declared = array();
foreach(explode("\n", $lines) as $num => $line)
{
$matches = null;
if (preg_match('/class\s+([^ ]+)/', $line, $matches))
{
$declared[] = $matches[1];
}
}
$namespace = '';
$use = array();
$allways = array('self', 'parent', 'static');
@ -69,7 +79,7 @@ function check_namespace($file)
{
$parts = explode('\\', $class);
$first_part = array_shift($parts);
if (in_array($class, $allways) || $class[0] == '\\' || in_array($first_part, $use))
if (in_array($class, $allways) || in_array($class, $declared) || $class[0] == '\\' || in_array($first_part, $use))
{
unset($all_matches[$c]);
continue;