1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- declare(strict_types=1);
- namespace PhpCsFixer\Tests\Test;
- use PhpCsFixer\AccessibleObject\AccessibleObject;
- use PhpCsFixer\Tokenizer\Token;
- use PhpCsFixer\Tokenizer\Tokens;
- use PhpCsFixer\Tokenizer\Transformers;
- class TokensWithObservedTransformers extends Tokens
- {
-
- public $currentTransformer;
-
- public $observedModificationsPerTransformer = [];
- public function offsetSet($index, $newval): void
- {
- if (null !== $this->currentTransformer) {
- $this->observedModificationsPerTransformer[$this->currentTransformer][] = $this->extractTokenKind($newval);
- }
- parent::offsetSet($index, $newval);
- }
-
- protected function applyTransformers(): void
- {
- $this->observedModificationsPerTransformer = [];
- $transformers = Transformers::createSingleton();
- foreach (AccessibleObject::create($transformers)->items as $transformer) {
- $this->currentTransformer = $transformer->getName();
- $this->observedModificationsPerTransformer[$this->currentTransformer] = [];
- foreach ($this as $index => $token) {
- $transformer->process($this, $token, $index);
- }
- }
- $this->currentTransformer = null;
- }
-
- private function extractTokenKind($token)
- {
- return $token instanceof Token
- ? ($token->isArray() ? $token->getId() : $token->getContent())
- : (\is_array($token) ? $token[0] : $token);
- }
- }
|