33
2
mirror of https://github.com/joomla-extensions/jedchecker.git synced 2024-11-30 08:44:02 +00:00

resolve aliases before checking framework rules

This commit is contained in:
Denis Ryabov 2023-10-01 18:45:34 +04:00
parent 5821e266ae
commit 16c593f3ad
2 changed files with 22 additions and 0 deletions

View File

@ -399,4 +399,25 @@ abstract class JEDCheckerHelper
{
return str_repeat("\n", substr_count($content, "\n"));
}
public static function resolveAliases($content)
{
if (preg_match_all('/\buse\s+([\\\\\w]+)(?:\s+as\s+(\w+))?\s*;/i', $content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$fqn = $match[1];
if (isset($match[2])) {
$alias = $match[2];
} else {
$path = explode('\\', $fqn);
$alias = $path[count($path) - 1];
}
$content = str_replace($match[0], self::cleanLines($match[0]), $content);
$content = preg_replace('/\b' . $alias . '\b/', $fqn, $content);
}
}
return $content;
}
}

View File

@ -173,6 +173,7 @@ class JedcheckerRulesFramework extends JEDcheckerRule
$content,
JEDCheckerHelper::CLEAN_HTML | JEDCheckerHelper::CLEAN_COMMENTS | JEDCheckerHelper::CLEAN_STRINGS
);
$cleanContent = JEDCheckerHelper::resolveAliases($cleanContent);
// Check short PHP tag
if (preg_match('/<\?\s/', $cleanContent, $match, PREG_OFFSET_CAPTURE))