Conditions | 2 |
Paths | 2 |
Total Lines | 25 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
43 | 88 | public function transform( string $segment ): string { |
|
44 | |||
45 | 88 | $sprintfLocker = new SprintfLocker( $this->pipeline->getSource(), $this->pipeline->getTarget() ); |
|
46 | |||
47 | // placeholding |
||
48 | 88 | $segment = $sprintfLocker->lock( $segment ); |
|
49 | |||
50 | // Octal parsing is disabled due to Hungarian percentages 20%-os |
||
51 | 88 | $regex = '/(?:\x25\x25)|(\x25(?:(?:[1-9]\d*)\$|\((?:[^\)]+)\))?(?:\+)?(?:0|[+-]?\'[^$])?(?:-)?(?:\d+)?(?:\.(?:\d+))?((?:[hjlqtzL]{0,2}[ac-giopsuxAC-GOSUX]{1})(?![\d\w])|(?:#@[\w]+@)|(?:@)))/'; |
|
52 | |||
53 | |||
54 | 88 | preg_match_all( $regex, $segment, $vars, PREG_SET_ORDER ); |
|
55 | 88 | foreach ( $vars as $variable ) { |
|
56 | |||
57 | //replace subsequent elements excluding already encoded |
||
58 | 4 | $segment = preg_replace( |
|
59 | 4 | '/' . preg_quote( $variable[ 0 ], '/' ) . '/', |
|
60 | 4 | '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::SPRINTF . '" equiv-text="base64:' . base64_encode( $variable[ 0 ] ) . '"/>', |
|
61 | 4 | $segment, |
|
62 | 4 | 1 |
|
63 | 4 | ); |
|
64 | } |
||
65 | |||
66 | //revert placeholding |
||
67 | 88 | return $sprintfLocker->unlock( $segment ); |
|
68 | } |
||
70 | } |