| Conditions | 4 |
| Paths | 5 |
| Total Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 4.25 |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | 10 | public function transform($value, $key = null, ParameterBag $item = null) |
|
| 12 | { |
||
| 13 | 10 | if (is_null($value)) { |
|
| 14 | return $value; |
||
| 15 | } |
||
| 16 | |||
| 17 | 10 | if (is_scalar($value)) { |
|
| 18 | 10 | $value = (string) $value; |
|
| 19 | } |
||
| 20 | |||
| 21 | 10 | if (!is_string($value)) { |
|
| 22 | throw new TransformationFailedException( |
||
| 23 | sprintf('Expected a string to transform, got %s instead', json_encode($value)) |
||
| 24 | ); |
||
| 25 | } |
||
| 26 | |||
| 27 | 10 | $value = preg_replace('/\n{1,}/', ' ', $value); // replace newlines with single newline |
|
| 28 | 10 | $value = preg_replace('/ {2,}/', ' ', $value); // replace double spaces with single space |
|
| 29 | 10 | $value = trim($value); // trim leading and trailing spaces |
|
| 30 | |||
| 31 | 10 | return $value; |
|
| 32 | } |
||
| 33 | } |
||
| 34 |