Skip to content

Commit da382de

Browse files
committed
PHP 8.3 updates
1 parent 8a0f73b commit da382de

File tree

9 files changed

+60
-55
lines changed

9 files changed

+60
-55
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"type": "library",
44
"require": {
55
"php": "^8.3",
6-
"ayesh/curl-fetcher": "^2.0.0"
6+
"ayesh/curl-fetcher": "^2.0.0",
7+
"ext-curl": "*"
78
},
89
"require-dev": {
910
"phpunit/phpunit": "^11.0.6"

src/CommitFetcher.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use Ayesh\CurlFetcher\CurlFetcher;
66
class CommitFetcher {
7-
private const API_ENDPOINT_COMPARE = 'https://api.github.com/repos/php/php-src/compare/';
8-
private const API_ENDPOINT_COMMIT_LIST = 'https://api.github.com/repos/php/php-src/commits';
9-
private ?string $apiKey = null;
7+
private const string API_ENDPOINT_COMPARE = 'https://api.github.com/repos/php/php-src/compare/';
8+
private const string API_ENDPOINT_COMMIT_LIST = 'https://api.github.com/repos/php/php-src/commits';
9+
private ?string $apiKey;
1010
private CurlFetcher $curlFetcher;
1111

1212
public function __construct(string $apiKey = null) {
@@ -79,8 +79,4 @@ public function getCommitListBetweenTags(string $startTag, string $untilTag): ar
7979

8080
return $return;
8181
}
82-
83-
public function getCommitByTag(string $tagName): \stdClass {
84-
https://api.github.com/repos/OWNER/REPO/git/tags/TAG_SHA
85-
}
8682
}

src/CommitFormatter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace PHPWatch\PHPCommitBuilder;
44

5+
use stdClass;
6+
57
class CommitFormatter {
68

79
use FormatterHelpers;
810
private array $commitsList = [];
911
private array $commitsGroupedByAuthor = [];
1012

11-
private array $nameReplacements = [];
13+
private array $nameReplacements;
1214

1315
public function __construct(array $inputCommits, array $nameReplacements = []) {
1416
$this->nameReplacements = $nameReplacements;
@@ -55,7 +57,7 @@ private function groupByAuthorNames(): void {
5557
ksort($this->commitsGroupedByAuthor, SORT_NATURAL | SORT_FLAG_CASE);
5658
}
5759

58-
private function splitCommit(\stdClass $commit): array {
60+
private function splitCommit(stdClass $commit): array {
5961
$commitMessage = $commit->commit->message;
6062
$commitMessageParts = explode("\n", $commitMessage, 2);
6163

src/DownloadLinkFetcher.php

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ public function getLinksForTag(string $tag): array {
2222
return $return;
2323
}
2424

25-
private static function determineVCVersion(string $tag): string {
26-
if (preg_match('/^php-7\.2\./', $tag)) {
27-
return 'VC15';
28-
}
29-
if (preg_match('/^php-7\.3\./', $tag)) {
30-
return 'VC15';
31-
}
32-
if (preg_match('/^php-7\.4\./', $tag)) {
33-
return 'vc15';
34-
}
35-
return 'vs16';
36-
}
25+
private static function determineVCVersion(string $tag): string {
26+
if (preg_match('/^php-7\.2\./', $tag)) {
27+
return 'VC15';
28+
}
29+
if (preg_match('/^php-7\.3\./', $tag)) {
30+
return 'VC15';
31+
}
32+
if (preg_match('/^php-7\.4\./', $tag)) {
33+
return 'vc15';
34+
}
35+
return 'vs16';
36+
}
3737

3838
private function getWindowsLinks(string $tag): array {
3939
$folder = 'releases/archives';
@@ -44,7 +44,7 @@ private function getWindowsLinks(string $tag): array {
4444
$folder_alt = 'qa';
4545
}
4646

47-
$vsVersion = self::determineVCVersion($tag);
47+
$vsVersion = self::determineVCVersion($tag);
4848

4949
return [
5050
'x64NTS' => [
@@ -76,20 +76,24 @@ private function getMultiUrlStatus(array $urlsets): array {
7676

7777
$handlers[$type][$i] = $ch;
7878

79-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
80-
curl_setopt($ch, CURLOPT_HEADER, true);
81-
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP);
82-
curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS);
83-
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
84-
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
85-
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
86-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
87-
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
88-
curl_setopt($ch, CURLOPT_ENCODING, '');
89-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
90-
curl_setopt($ch, CURLOPT_TCP_KEEPALIVE, 1);
91-
curl_setopt($ch, CURLOPT_NOBODY, true);
92-
curl_setopt($ch, CURLOPT_USERAGENT, 'ayesh/curl-fetcher');
79+
curl_setopt_array($ch, [
80+
CURLOPT_RETURNTRANSFER => true,
81+
CURLOPT_PROTOCOLS, CURLPROTO_HTTPS => CURLPROTO_HTTP,
82+
CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTPS,
83+
CURLOPT_MAXREDIRS => 5,
84+
CURLOPT_TIMEOUT => 10,
85+
CURLOPT_SSL_VERIFYHOST => 2,
86+
CURLOPT_SSL_VERIFYPEER => true,
87+
CURLOPT_SSL_OPTIONS => CURLSSLOPT_NATIVE_CA,
88+
CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2,
89+
CURLOPT_ENCODING => '',
90+
CURLOPT_FOLLOWLOCATION => true,
91+
CURLOPT_TCP_KEEPALIVE => 1,
92+
CURLOPT_USERAGENT => 'ayesh/curl-fetcher',
93+
94+
CURLOPT_NOBODY => true,
95+
CURLOPT_HEADER => true,
96+
]);
9397

9498
curl_multi_add_handle($cm, $ch);
9599
}
@@ -102,8 +106,8 @@ private function getMultiUrlStatus(array $urlsets): array {
102106

103107
$completedUrls = [];
104108

105-
foreach ($handlers as $type => $urls) {
106-
foreach ($urls as $i => $url) {
109+
foreach ($handlers as $urls) {
110+
foreach ($urls as $url) {
107111
if (curl_getinfo($url, CURLINFO_HTTP_CODE) === 200) {
108112
$completedUrls[curl_getinfo($url, CURLINFO_EFFECTIVE_URL)] = curl_multi_getcontent($url);
109113
}

src/FormatterHelpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPWatch\PHPCommitBuilder;
44

55
trait FormatterHelpers {
6-
private const EOL = "\r\n";
6+
private const string EOL = "\r\n";
77

88
private static function markdownTitle(string $title): string {
99
return '### ' . self::plainText($title) . static::EOL;

src/KeywordEnhancer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPWatch\PHPCommitBuilder;
44

55
class KeywordEnhancer {
6-
protected const CODIFY_PATTERNS = [
6+
protected const array CODIFY_PATTERNS = [
77
'/\b(?<!`)(?:zend|php)_[a-z_]+\(\)(?!`)/i', // zend_foo_bar()
88
'/\b(?<!`)(?:zend|php|_php)_[a-z_*]+\b(?![`.(=])\*?/i', // zend_foo_bar
99
'/\b(?<![`\/])[a-z][a-z\d_-]+(.stubs?)?\.(phpt?|c|h)(?![`.?])/', // run-tests.php / foo.stub.php foo.stubs.php / test-foo-bar.phpt,

src/NewsFetcher.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44

55
use Ayesh\CurlFetcher\CurlFetcher;
66

7+
use function sprintf;
8+
79
class NewsFetcher {
8-
private const RAW_CONTENT_URL = 'https://raw.githubusercontent.com/php/php-src/%tag/NEWS';
10+
private const string RAW_CONTENT_URL = 'https://raw.githubusercontent.com/php/php-src/%tag/NEWS';
911

10-
private const REGEX_PIPE_HEADER = '/^\|+$/';
11-
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)?))$/';
12-
private const REGEX_EXT_HEADER = '/^- ?(?<ext_name>[A-Za-z][A-Za-z _\/\d]+):? ?$/';
12+
private const string REGEX_PIPE_HEADER = '/^\|+$/';
13+
private const string 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)?))$/';
14+
private const string REGEX_EXT_HEADER = '/^- ?(?<ext_name>[A-Za-z][A-Za-z _\/\d]+):? ?$/';
1315

14-
private const REGEX_CHANGE_RECORD_START = '/^ ? ?(\.|-) (?<change_record>.*)$/';
15-
private const REGEX_CHANGE_RECORD_CONTINUATION = '/^( ?|\t)(?<change_record_cont>.*)$/';
16+
private const string REGEX_CHANGE_RECORD_START = '/^ ? ?(\.|-) (?<change_record>.*)$/';
17+
private const string REGEX_CHANGE_RECORD_CONTINUATION = '/^( ?|\t)(?<change_record_cont>.*)$/';
1618

17-
private ?string $apiKey = null;
19+
private ?string $apiKey;
1820
private CurlFetcher $curlFetcher;
1921

2022
private array $staticReplacements = [];
@@ -120,7 +122,7 @@ private function parseNewsPage(string $contents): array {
120122

121123
if ($lastLine === null) {
122124
throw new \RuntimeException(
123-
\sprintf(
125+
sprintf(
124126
"Cursor last line number should not be empty when detecting a continuation of a change record on line %d:\r\n%s",
125127
$lineNo,
126128
$line
@@ -134,7 +136,7 @@ private function parseNewsPage(string $contents): array {
134136
continue;
135137
}
136138

137-
throw new \Exception(\sprintf("Unknown line format at line %d:\r\n%s", $lineNo, $line));
139+
throw new \Exception(sprintf("Unknown line format at line %d:\r\n%s", $lineNo, $line));
138140
}
139141

140142
return $releases;

src/NewsFormatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function getNewsListForRelease(string $version): array {
2828

2929
$version = $this->releases[$version];
3030

31-
foreach ($version['changes'] as $ext => &$changes) {
31+
foreach ($version['changes'] as &$changes) {
3232
foreach ($changes as &$change) {
3333
$change = $this->removeAuthorInBraces($change);
3434
$change = KeywordEnhancer::enhance($change);
@@ -62,7 +62,7 @@ public function getNewsListForReleaseMarkup(string $version): string {
6262
}
6363

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

6767
return $change;
6868
}

src/TagListFetcher.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
use stdClass;
77

88
class TagListFetcher {
9-
private const API_ENDPOINT_TAG_LIST = 'https://api.github.com/repos/php/php-src/tags';
10-
private const API_ENDPOINT_TAG_INDIVIDUAL = 'https://api.github.com/repos/php/php-src/git/commits/%tag';
9+
private const string API_ENDPOINT_TAG_LIST = 'https://api.github.com/repos/php/php-src/tags';
10+
private const string API_ENDPOINT_TAG_INDIVIDUAL = 'https://api.github.com/repos/php/php-src/git/commits/%tag';
1111

12-
private const REGEX_TAG_PATTERN = '/^php-\d\.\d\.(?:\d\d?|0(?:alpha\d|beta\d|rc\d|RC\d)?)$/i';
12+
private const string REGEX_TAG_PATTERN = '/^php-\d\.\d\.(?:\d\d?|0(?:alpha\d|beta\d|rc\d|RC\d)?)$/i';
1313
private ?string $apiKey;
1414
private CurlFetcher $curlFetcher;
1515

0 commit comments

Comments
 (0)