Skip to content

Commit 36c5548

Browse files
committed
Update NewsFetcher to support static text replacements externally
1 parent 0bc7cce commit 36c5548

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/NewsFetcher.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ class NewsFetcher {
1717
private ?string $apiKey = null;
1818
private CurlFetcher $curlFetcher;
1919

20-
private const STATIC_REPLACEMENTS = [
21-
' (Anatol)' => ' (Anatol)',
22-
' (Kalle)' => ' (Kalle)',
23-
];
20+
private array $staticReplacements = [];
2421

2522
public function __construct(string $apiKey = null) {
2623
$this->apiKey = $apiKey;
2724
$this->curlFetcher = new CurlFetcher();
2825
}
2926

27+
public function setReplacements(array $replacements): void {
28+
$this->staticReplacements = $replacements;
29+
}
30+
3031
public function fetchAllForVersion(int|string $version): array {
3132
if (is_string($version)) {
3233
if ($version !== 'master') {
@@ -70,8 +71,8 @@ private function parseNewsPage(string $contents): array {
7071
$lineNo = (int)$lineNo;
7172
++$lineNo; // Line numbers start from 1, although the array index starts at 0
7273

73-
if (isset(self::STATIC_REPLACEMENTS[$line])) {
74-
$line = self::STATIC_REPLACEMENTS[$line];
74+
if (isset($this->staticReplacements[$line])) {
75+
$line = $this->staticReplacements[$line];
7576
}
7677

7778
// Should skip line?

0 commit comments

Comments
 (0)