Skip to content

Commit 3fda829

Browse files
committed
Update pattern matching
1 parent 2518b2b commit 3fda829

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/NewsFetcher.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@ class NewsFetcher {
77
private const RAW_CONTENT_URL = 'https://raw.githubusercontent.com/php/php-src/%tag/NEWS';
88

99
private const REGEX_PIPE_HEADER = '/^\|+$/';
10-
private const REGEX_RELEASE_HEADER = '/^(?<date>(?<day>\d\d|\?\?) (?<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|\?\?\?) (?<year>\?\?\?\?|20\d\d)), PHP (?<release_id>\d\.\d\.(?:\d\d?|0(?:alpha\d|beta\d|rc\d|RC\d)?))$/';
11-
private const REGEX_EXT_HEADER = '/^- (?<ext_name>[A-Za-z][A-Za-z _\/\d]+):?$/';
10+
private const REGEX_RELEASE_HEADER = '/^(?<date>(?<day>\d\d?|\?\?) (?<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|\?\?\?) (?<year>\?\?\?\?|20\d\d)), (PHP|php) (?<release_id>\d\.\d\.(?:\d\d?|0(?:alpha\d|beta\d|rc\d|RC\d)?))$/';
11+
private const REGEX_EXT_HEADER = '/^- ?(?<ext_name>[A-Za-z][A-Za-z _\/\d]+):? ?$/';
1212

13-
private const REGEX_CHANGE_RECORD_START = '/^ \. (?<change_record>.*)$/';
14-
private const REGEX_CHANGE_RECORD_CONTINUATION = '/^ (?<change_record_cont>.*)$/';
13+
private const REGEX_CHANGE_RECORD_START = '/^ ? ?(\.|-) (?<change_record>.*)$/';
14+
private const REGEX_CHANGE_RECORD_CONTINUATION = '/^( ?|\t)(?<change_record_cont>.*)$/';
1515

1616
private ?string $apiKey = null;
1717
private CurlFetcher $curlFetcher;
1818

19+
private const STATIC_REPLACEMENTS = [
20+
' (Anatol)' => ' (Anatol)',
21+
' (Kalle)' => ' (Kalle)',
22+
];
23+
1924
public function __construct(string $apiKey = null) {
2025
$this->apiKey = $apiKey;
2126
$this->curlFetcher = new CurlFetcher();
@@ -66,6 +71,9 @@ private function parseNewsPage(string $contents): array {
6671
$lineNo = (int) $lineNo;
6772
++$lineNo; // Line numbers start from 1, although the array index starts at 0
6873

74+
if (isset(self::STATIC_REPLACEMENTS[$line])) {
75+
$line = self::STATIC_REPLACEMENTS[$line];
76+
}
6977

7078
// Should skip line?
7179
if ($this->skipLine($line, $lineNo)) {
@@ -109,7 +117,7 @@ private function parseNewsPage(string $contents): array {
109117
}
110118

111119
if ($lastLine === null) {
112-
throw new \RuntimeException('Cursor last line number should not be empty when detecting a continuation of a change record');
120+
throw new \RuntimeException(\sprintf("Cursor last line number should not be empty when detecting a continuation of a change record on line %d:\r\n%s", $lineNo, $line));
113121
}
114122

115123
// is this continuation of a line?

src/NewsFormatter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function __construct(array $releases) {
1111

1212
public function getNewsListForRelease(string $version): array {
1313
if (!isset($this->releases[$version])) {
14-
return [];
14+
return [];
1515
}
1616

1717
if (!isset($this->releases[$version]['version'], $this->releases[$version]['changes'])) {
@@ -38,9 +38,9 @@ public function getNewsListForRelease(string $version): array {
3838
public function getNewsListForReleaseMarkup(string $version): string {
3939
$release = $this->getNewsListForRelease($version);
4040

41-
if (empty($release)) {
42-
return '';
43-
}
41+
if (empty($release)) {
42+
return '';
43+
}
4444

4545
$output = '';
4646

@@ -58,7 +58,7 @@ public function getNewsListForReleaseMarkup(string $version): string {
5858
}
5959

6060
private function removeAuthorInBraces(string $change): string {
61-
$change = preg_replace('/(^(.*))( \([\w\p{L} ,-]+\).?$)/u', '$1', $change, 1, $count);
61+
$change = preg_replace('/(^(.*))( \([\w\p{L} ,-]+\).?$)/u', '$1', $change, 1, $count);
6262

6363
return $change;
6464
}

0 commit comments

Comments
 (0)