| Conditions | 3 |
| Paths | 3 |
| Total Lines | 24 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 30 | 86 | public function transform( string $segment ): string { |
|
| 31 | |||
| 32 | /* |
||
| 33 | * Examples: |
||
| 34 | * - %{# } |
||
| 35 | * - %{\n}$spaces=2%{\n} |
||
| 36 | * - %{vars} |
||
| 37 | * |
||
| 38 | */ |
||
| 39 | 86 | preg_match_all( '/%{(?!<ph )[^{}]*?}/', $segment, $html, PREG_SET_ORDER ); |
|
| 40 | 86 | foreach ( $html as $pos => $ruby_variable ) { |
|
| 41 | //check if inside twig variable there is a tag because in this case shouldn't replace the content with PH tag |
||
| 42 | 3 | if ( !strstr( $ruby_variable[ 0 ], ConstantEnum::GTPLACEHOLDER ) ) { |
|
| 43 | //replace subsequent elements excluding already encoded |
||
| 44 | 3 | $segment = preg_replace( |
|
| 45 | 3 | '/' . preg_quote( $ruby_variable[ 0 ], '/' ) . '/', |
|
| 46 | 3 | '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::RUBY_ON_RAILS . '" equiv-text="base64:' . base64_encode( $ruby_variable[ 0 ] ) . '"/>', |
|
| 47 | 3 | $segment, |
|
| 48 | 3 | 1 |
|
| 49 | 3 | ); |
|
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | 86 | return $segment; |
|
| 54 | } |
||
| 56 | } |