forked from symplify/coding-standard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodNameResolver.php
More file actions
44 lines (33 loc) · 1.05 KB
/
MethodNameResolver.php
File metadata and controls
44 lines (33 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
declare(strict_types=1);
namespace Symplify\CodingStandard\Fixer\Naming;
use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
final class MethodNameResolver
{
/**
* @param Tokens<Token> $tokens
*/
public function resolve(Tokens $tokens, int $currentPosition): ?string
{
foreach ($tokens as $position => $token) {
if ($position <= $currentPosition) {
continue;
}
if (! $token->isGivenKind([T_FUNCTION])) {
continue;
}
$nextNextMeaningfulTokenIndex = $tokens->getNextMeaningfulToken($position + 1);
if (null === $nextNextMeaningfulTokenIndex) {
continue;
}
$nextNextMeaningfulToken = $tokens[$nextNextMeaningfulTokenIndex];
// skip anonymous functions
if (! $nextNextMeaningfulToken->isGivenKind(T_STRING)) {
continue;
}
return $nextNextMeaningfulToken->getContent();
}
return null;
}
}