Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| TracingTrait | |
0.00% |
0 / 32 |
|
0.00% |
0 / 6 |
90 | |
0.00% |
0 / 1 |
| init | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| traceEvent | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
20 | |||
| onCompoundTk | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| resetState | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setPipelineId | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| isDisabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | // @phan-file-suppress PhanUndeclaredProperty |
| 5 | |
| 6 | namespace Wikimedia\Parsoid\Wt2Html\TT; |
| 7 | |
| 8 | use Wikimedia\Parsoid\Tokens\CompoundTk; |
| 9 | use Wikimedia\Parsoid\Tokens\Token; |
| 10 | |
| 11 | trait TracingTrait { |
| 12 | private string $traceType; |
| 13 | private TokenHandler $handler; |
| 14 | private string $name; |
| 15 | |
| 16 | private function init( string $traceType, TokenHandler $handler ): void { |
| 17 | $this->traceType = $traceType; |
| 18 | $this->handler = $handler; |
| 19 | $this->name = ( new \ReflectionClass( $handler ) )->getShortName(); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @param string $func |
| 24 | * @param string|Token $token |
| 25 | * @return ?array<string|Token> |
| 26 | */ |
| 27 | protected function traceEvent( string $func, $token ): ?array { |
| 28 | $this->env->trace( |
| 29 | $this->traceType, $this->pipelineId, |
| 30 | fn () => str_pad( $this->name, 23, ' ', STR_PAD_LEFT ) . "| ", |
| 31 | $token |
| 32 | ); |
| 33 | |
| 34 | $profile = $this->manager->profile; |
| 35 | if ( $profile ) { |
| 36 | $s = hrtime( true ); |
| 37 | if ( $func === 'onCompoundTk' ) { |
| 38 | '@phan-var CompoundTk $token'; |
| 39 | '@phan-var Tokenhandler $this'; |
| 40 | $res = $this->handler->$func( $token, $this ); |
| 41 | } else { |
| 42 | $res = $this->handler->$func( $token ); |
| 43 | } |
| 44 | $t = hrtime( true ) - $s; |
| 45 | $traceName = "{$this->name}::$func"; |
| 46 | $profile->bumpTimeUse( $traceName, $t, "TT" ); |
| 47 | $profile->bumpCount( $traceName ); |
| 48 | $this->manager->tokenTimes += $t; |
| 49 | } else { |
| 50 | if ( $func === 'onCompoundTk' ) { |
| 51 | '@phan-var CompoundTk $token'; |
| 52 | '@phan-var Tokenhandler $this'; |
| 53 | $res = $this->handler->$func( $token, $this ); |
| 54 | } else { |
| 55 | $res = $this->handler->$func( $token ); |
| 56 | } |
| 57 | } |
| 58 | return $res; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @return ?list<string|Token> |
| 63 | */ |
| 64 | public function onCompoundTk( CompoundTk $token, TokenHandler $tokensHandler ): ?array { |
| 65 | return $this->traceEvent( 'onCompoundTk', $token ); |
| 66 | } |
| 67 | |
| 68 | public function resetState( array $options ): void { |
| 69 | $this->handler->resetState( $options ); |
| 70 | } |
| 71 | |
| 72 | public function setPipelineId( int $id ): void { |
| 73 | $this->pipelineId = $id; |
| 74 | $this->handler->setPipelineId( $id ); |
| 75 | } |
| 76 | |
| 77 | public function isDisabled(): bool { |
| 78 | return $this->handler->isDisabled(); |
| 79 | } |
| 80 | } |