forked from symplify/coding-standard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokenReverser.php
More file actions
30 lines (25 loc) · 875 Bytes
/
TokenReverser.php
File metadata and controls
30 lines (25 loc) · 875 Bytes
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
<?php
declare(strict_types=1);
namespace Symplify\CodingStandard\TokenRunner\Traverser;
use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
final class TokenReverser
{
/**
* By convention, tokens should be traversed from the bottom to the top. That way an added node from the bottom,
* doesn't change index keys of the nodes on the top that are yet to be check.
*
* Traversing nodes from the top to the bottom would change the index keys of nodes on the bottom, and would create
* breaking situations.
*
* @param Tokens<Token> $tokens
* @return Token[]
*/
public function reverse(Tokens $tokens): array
{
$reversedTokens = array_reverse($tokens->toArray(), true);
// remove null values
// @phpstan-ignore arrayFilter.same
return array_filter($reversedTokens);
}
}