Skip to content

Commit

Permalink
fix: Fix hook reference
Browse files Browse the repository at this point in the history
  • Loading branch information
gchtr committed Sep 18, 2024
1 parent 8c9463d commit 533b163
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/Compiler/HookReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function parse()
$type = $entry[0];
$contents = $entry[1];

if (T_DOC_COMMENT === $type) {
if ('T_DOC_COMMENT' === $type) {
$docBlockFactory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
$docBlock = $docBlockFactory->create($contents);

Expand Down Expand Up @@ -217,6 +217,8 @@ private function isHook($name)

private function getHookType($name)
{
// Trim leading slashes.
$name = ltrim($name, '\\');
$name = explode('_', $name);
$name = reset($name);

Expand All @@ -240,7 +242,7 @@ private function isHookComment($docBlock)
$keywords = ['Filters', 'Fires'];

foreach ($keywords as $keyword) {
if (substr($docBlock->getSummary(), 0, mb_strlen($keyword)) === $keyword) {
if (str_starts_with($docBlock->getSummary(), $keyword)) {
return true;
}
}
Expand All @@ -252,6 +254,17 @@ private function getTokens()
{
$tokens = token_get_all($this->file->getSource());

return $tokens;
foreach ($tokens as &$token){
if (is_array($token)) {
$token[0] = token_name($token[0]);
}
}

// Filter out whitespace tokens.
$tokens = array_filter($tokens, function ($token) {
return !is_array($token) || !in_array($token[0], ['T_WHITESPACE']);
});

return array_values($tokens);
}
}

0 comments on commit 533b163

Please sign in to comment.