Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| DependabotChangelogEntryMessageResolver | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| resolve | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * Fast Forward Development Tools for PHP projects. |
| 7 | * |
| 8 | * This file is part of fast-forward/dev-tools project. |
| 9 | * |
| 10 | * @author Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 11 | * @license https://opensource.org/licenses/MIT MIT License |
| 12 | * |
| 13 | * @see https://github.com/php-fast-forward/ |
| 14 | * @see https://github.com/php-fast-forward/dev-tools |
| 15 | * @see https://github.com/php-fast-forward/dev-tools/issues |
| 16 | * @see https://php-fast-forward.github.io/dev-tools/ |
| 17 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 18 | */ |
| 19 | |
| 20 | namespace FastForward\DevTools\Changelog; |
| 21 | |
| 22 | use function Safe\preg_replace; |
| 23 | use function Safe\preg_match; |
| 24 | |
| 25 | /** |
| 26 | * Normalizes minimal changelog entry messages for Dependabot pull requests. |
| 27 | */ |
| 28 | class DependabotChangelogEntryMessageResolver |
| 29 | { |
| 30 | /** |
| 31 | * @param string $title |
| 32 | * @param int $pullRequestNumber |
| 33 | * |
| 34 | * @return string |
| 35 | */ |
| 36 | public function resolve(string $title, int $pullRequestNumber): string |
| 37 | { |
| 38 | $message = preg_replace('/\s+/', ' ', trim($title)) ?? trim($title); |
| 39 | $message = rtrim($message, " \t\n\r\0\x0B."); |
| 40 | |
| 41 | if (1 === preg_match('/\(#\d+\)$/', $message)) { |
| 42 | return $message; |
| 43 | } |
| 44 | |
| 45 | return \sprintf('%s (#%d)', $message, $pullRequestNumber); |
| 46 | } |
| 47 | } |