Files
KanbanGit/app/Actions/Git/BuildSuggestedTicketBranchName.php

29 lines
614 B
PHP

<?php
namespace App\Actions\Git;
use App\Models\Ticket;
use Illuminate\Support\Str;
class BuildSuggestedTicketBranchName
{
public function handle(Ticket $ticket): string
{
$titleSlug = Str::of($ticket->title)
->lower()
->replaceMatches('/[^a-z0-9\s-]+/', '')
->trim()
->replaceMatches('/\s+/', '-')
->replaceMatches('/-+/', '-')
->value();
$ticketKey = Str::lower($ticket->ticket_key);
if ($titleSlug === '') {
return $ticketKey;
}
return "{$ticketKey}-{$titleSlug}";
}
}