Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.

Commit 116b2e2

Browse files
Use a more generic approach for formatting labels
1 parent 5cac427 commit 116b2e2

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

tests/src/extension/DotRenderer.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
namespace example\framework\event\test\extension;
33

44
use function assert;
5+
use function explode;
56
use function file_get_contents;
67
use function implode;
78
use function is_string;
9+
use function mb_strlen;
810
use function sprintf;
911
use function str_replace;
1012

@@ -84,10 +86,27 @@ public function render(array $given, string $when, array $then): string
8486
*/
8587
private function formatLabel(string $label): string
8688
{
87-
return str_replace(
88-
['at price', 'from'],
89-
['\nat price', '\nfrom'],
90-
$label,
91-
);
89+
$words = explode(' ', $label);
90+
$lines = [];
91+
$line = '';
92+
93+
foreach ($words as $word) {
94+
if (mb_strlen($line) + mb_strlen($word) > 22) {
95+
$lines[] = $line;
96+
$line = '';
97+
}
98+
99+
if ($line === '') {
100+
$line = $word;
101+
102+
continue;
103+
}
104+
105+
$line .= ' ' . $word;
106+
}
107+
108+
$lines[] = $line;
109+
110+
return implode('\n', $lines);
92111
}
93112
}

0 commit comments

Comments
 (0)