in src/shipit/filter/ShipItConditionalLinesFilter.php [83:114]
private static function process(
ShipItChangeset $changeset,
?string $path_regex,
string $pattern,
string $replacement,
): ShipItChangeset {
$diffs = vec[];
foreach ($changeset->getDiffs() as $diff) {
$_matches = vec[];
if (
$path_regex is nonnull &&
!PHP\preg_match($path_regex, $diff['path'], inout $_matches)
) {
$diffs[] = $diff;
continue;
}
$diff['body'] = Str\split($diff['body'], "\n")
|> Vec\map(
$$,
$line ==> PHP\preg_replace(
$pattern,
$replacement,
$line, /* limit */
1,
) as ?string ??
$line, // if input length === 0, then `null` is returned
)
|> Str\join($$, "\n");
$diffs[] = $diff;
}
return $changeset->withDiffs($diffs);
}